Home Using constexpr in a type dependent context
Reply: 0

Using constexpr in a type dependent context

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.

share|improve this question
  • 9
    constexpr int is not a type – Justin Jan 10 at 20:24
  • 1
    "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
  • 2
    @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

1 Answer 1

active oldest votes
up vote 1 down vote accepted
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO