Slizzered Slizzered - 1 year ago 167
C++ Question

C++ concepts lite and type alias declaration

Is it possible to use

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

#include <type_traits>

template<typename T>
concept bool TestConcept ()
return requires(T t)
using V = T;

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

Answer Source

No. According to the concepts TS, a requirement is:


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download