templates - complex constexpr alternatives -


consider

typedef std::complex<double> complex; complex complexexpresion(int a) {return complex(0,-a);} 

since 1 cannot write

template<typename d>     struct {   static constexpr complex value = complexexpresion(d::value); }; 

as alternative 1 writes

template<typename d>  struct b {   static const complex value;  };  template<typename d>  const complex b<d>::value = complexexpresion(d::value); 

consider

template<typename d, int n>  struct c;  template<typename d>  struct c<d,1> {   static const complex value;  };  template<typename d>  const complex c<d,1>::value = b<d>::value; 

for reasone

struct data {     static auto constexpr value =2; };  int main() {         using c = c<data,1>;          std::cout << c::value; } 

prints correct value(which (0,-2) ) here same code prints (0,0) when complied msvc++

i have 2 questions

1) why on msvc++ , there known workaround?

2) there better alternative struct a struct b not same thing...

looks compiler bug unless i'm missing something. isn't answer, sharing found. smallest example deduce exhibits issue:

#include <iostream>  // using function important int func() { return 1; }  // template imporant template<class d> struct b {   static const int value; };  // defined outside block important template<class d> const int b<d>::value = func();  // going through c important struct c {   static const int value; };  const int c::value = b<int>::value;  int main() {   // should print 1 prints 0   std::cout << c::value << std::endl; } 

surprisingly trips clang unless specify func constexpr or specify -stdlib=libc++ (at least on coliru)

i guess can fix issue skipping 1 of bits above. can static constexpr complex value = complexexpresion(d::value); if mark complexespression constexpr.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -