Reputation: 371
Easy question, is this legal?
template<class T>
struct foo {
using type = std::conditional<IF_CONDITION<T>::value, constexpr int, int>::type;
};
Compiler error: "error: "constexpr" is not valid here" Haven't been able to find any documentation on this. Because its a compile time condition it seems like this should be able to do in theory at least.
Upvotes: 1
Views: 503
Reputation: 4243
From the standard:
The constexpr specifier shall be applied only to the definition of a variable or variable template or the declaration of a function or function template. A function or static data member declared with the constexpr specifier is implicitly an inline function or variable (10.1.6). If any declaration of a function or function template has a constexpr specifier, then all its declarations shall contain the constexpr specifier. [ Note: An explicit specialization can differ from the template declaration with respect to the constexpr specifier. — end note ] [ Note: Function parameters cannot be declared constexpr. — end note ]
So constexpr is not supposed to be within the template parameter.
In your case you could create the type specialization alias with:
template<typename T>
using MyVec0 = Vector<T,0>;
Upvotes: 1