What's the point of unnamed non-type template parameters?

后端 未结 3 963
面向向阳花
面向向阳花 2020-12-19 13:28

According to the reference, the name of a non-type template parameter is optional, even when assigning a default value (see (1) and (2)). Therefore these template structs ar

3条回答
  •  无人及你
    2020-12-19 14:06

    What's the point of unnamed/anonymous non-type template parameters?

    I can think of specialization:

    template
    struct Foo{
       char x;
    };
    
    template<>
    struct Foo<0> {
       int x;
    };
    
    template<>
    struct Foo<1> {
       long x;
    };
    

    Then:

    Foo<0> a; // x data member is int
    Foo<1> b; // x data member is long
    Foo<7> c; // x data member is char
    Foo<>  d; // x data member is char
    

提交回复
热议问题