Consider this code:
struct A
{
template <typename T>
concept foo = true;
};
It doesn't compile. My Clang 10 gives me error: concept declarations may only appear in global or namespace scope
, and GCC says something similar.
Is there a reason why it's not allowed? I don't see why it couldn't work, even if the enclosing class was a template.
The fundamental difficulty that would arise is that concepts could become dependent:
Is
X
a non-type template parameter of (dependent) typeT::Q
(which does not requiretypename
in C++20), or is it a type template parameter constrained by the conceptT::Q
?The rule is that it’s the former; we would need new syntax (along the lines of
typename
/template
) to express the other possibility: perhaps something likeNo one has explored such an extension seriously, and it could easily conflict with other extensions to concept syntax that might be more valuable.