Home Using constexpr in a type dependent context

# Using constexpr in a type dependent context

user8886
1#
user8886 Published in September 19, 2018, 4:00 am

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.

• constexpr int is not a type – Justin Jan 10 at 20:24
• "const int" would be a type. "constexpr int" is not a type. – StPiere Jan 10 at 20:25
• I see, I thought it was comparable to const Do you know if their is any way to emulate this? (Other than class specialization) – Joseph Franciscus Jan 10 at 20:25
• @JosephFranciscus In what kind of code would you need something to be conditionally constexpr? Maybe we could help you with that. – Guillaume Racicot Jan 10 at 20:26
• I'm writing a library like Eigen So an object will be like Vector<class T, int Rows> if Rows == 0 than I want a dynamic Row value (IE regular int) else I want it to be constexpr (as it will be known at compile time) – Joseph Franciscus Jan 10 at 20:32