Does C++ define the behavior of the following code:
template <class T>
concept C = true;
struct C {};
template <C T>
struct A {};
template <struct C T>
struct B {};
int main() {
// when using MSVC
C c; // error
bool b = C<int>; // also error
// and can't use concept C anywhere other
// than the template parameter list
constexpr struct C cc {};
struct C c2; // ok
A<int> a; // ok
A<cc> a; // error
B<cc> b; // ok
return 0;
}
Can anyone answer me:
- Is this declaration correct ?
template <struct C T>
struct B {};
I found this on cppreference:
When used as a template argument, class T is a type template parameter named T, not an unnamed non-type parameter whose type T is introduced by elaborated type specifier
- As mentioned above, can I define a concept and a class type with the same name? If the answer is yes, how do I specify that the name is a concept?