Home Using constexpr in a type dependent context
Reply: 1

Using constexpr in a type dependent context

Joseph Franciscus
Joseph Franciscus Published in 2018-01-10 20:22:41Z

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.

StPiere Reply to 2018-01-10 20:36:52Z

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>;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313558 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO