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

后端 未结 3 970
面向向阳花
面向向阳花 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:11

    First, we can split declaration from definition. So name in declaration is not really helpful. and name might be used in definition

    template  struct Foo;
    template  struct Bar;
    
    template  struct Foo {/*..*/};
    template  struct Bar {/*..*/};
    

    Specialization is a special case of definition.

    Then name can be unused, so we might omit it:

    template 
    using always_t = T;
    
    template 
    struct MyArray, T>
    {
        MyArray(always_t... v) : /*..*/
    };
    

    or used for SFINAE

    template 
    struct some_sized_type;
    

提交回复
热议问题