Is it possible to use typedef
or using
to declare a type alias inside a concept, as proposed by the Concepts TS?
If I try something like the following MWE, the code does not compile (with gcc 6.2.1 and the -fconcepts
switch)
#include <type_traits>
template<typename T>
concept bool TestConcept ()
{
return requires(T t)
{
using V = T;
std::is_integral<V>::value;
};
}
int main()
{
return 0;
}
Resulting error:
main.cpp: In function ‘concept bool TestConcept()’:
main.cpp:8:9: error: expected primary-expression before ‘using’
using V = T;
^~~~~
main.cpp:8:9: error: expected ‘}’ before ‘using’
main.cpp:8:9: error: expected ‘;’ before ‘using’
main.cpp:4:14: error: definition of concept ‘concept bool TestConcept()’ has multiple statements
concept bool TestConcept ()
^~~~~~~~~~~
main.cpp: At global scope:
main.cpp:11:1: error: expected declaration before ‘}’ token
}
^
No. According to the concepts TS, a requirement is:
requirement:
simple-requirement
type-requirement
compound-requirement
nested-requirement
Where a simple-requirement is an expression followed by a ;
and a type-requirement is something like typename T::inner
. The other two sound like what the name suggests.
A type alias is a declaration, not an expression, and so does not meet the requirement of a requirement.