Consider the following simplified metaprogrammable template that implements the Angle class, which internally stores a reduced value modulo 360 degrees.
#include <iostream> #include <typeinfo> template<int N, int D> struct Modulus { static auto const value = N % D; }; template<int N> struct Angle { static auto const value = Modulus<N, 360>::value; // ERROR //static int const value = Modulus<N, 360>::value; // OK //static auto const value = N % 360; // OK typedef Angle<value> type; }; int main() { std::cout << typeid(Angle<30>::type).name() << "\n"; std::cout << typeid(Angle<390>::type).name() << "\n"; return 0; }
Conclusion on Ideone
With Visual C ++ 2010 Express, I can do static auto const = Modulus<N, 360>::value , but with MinGW gcc 4.7.2 ( Nuwen distro ) or Ideone (gcc 4.5.1) I must either explicitly designate the type as static int const value = Modulus<N, 360>::value , or I need to use auto with a full modular expression as static auto const value = N % 360; .
Question: Which compiler is correct in accordance with the new C ++ 11 standard?
source share