Just curious. According to C++17 and higher we can use an "auto" placeholder for non-type template parameters:
template<typename A, auto B>
class C {
public:
A foo() { return B; }
};
But can we pass instead of "auto" template type parameter defined at left?
example.cpp
template<typename A, A B>
class C {
public:
A foo() { return B; }
};
int main()
{
C<int, 5> c;
std::cout << c.foo() << std::endl;
return 0;
}
Well in practice we can, and clang with -std=c++11 allows to do that.
$ g++ -std=c++11 example.cpp
$ ./a.out
5
But what about standard? I didn't find any explicit rule. Thanks!
Aucun commentaire:
Enregistrer un commentaire