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

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

    Oh, you can access them!

    template  struct Foo {};
    
    template 
    int get(Foo) {
        return N;
    }
    
    int main() {
        Foo<3> foo;
        return get(foo);
    }
    

    This might be a bit contrived. But in general for some templates you don't want to name them and then it is convenient that you don't have to.

提交回复
热议问题