mercredi 19 avril 2017

C++11 templates code - failed to compile in XCode

I have this code:

template<bool, class _Ty1, class _Ty2> struct MyIf
{   // type is _Ty2 for assumed false
    typedef _Ty2 type;
};

template<class _Ty1, class _Ty2> struct MyIf<true, _Ty1, _Ty2>
{   // type is _Ty1 for assumed true
    typedef _Ty1 type;
};

template<class _Ty>
struct my_decay
{
    // determines decayed version of _Ty
    typedef typename std::decay<_Ty>::type _Ty1;

    typedef typename MyIf<
        std::is_arithmetic<_Ty1>::value, typename _Ty1, //(1)
        typename MyIf<
            std::is_same<LuaString, _Ty1>::value, typename _Ty1, //(2)

        typename _Ty //(3)
        >::type
    >::type type;
};

Under Visual Studio 2015, it compiles fine. However, when I port my code to XCode, I got the following errors:

  • for (1) => Expected a qualified name after "typename"
  • for (2) => Type name does not allow storage class to be specified
  • for (3) => Type name does not allow storage class to be specified

In Xcode, I have set C++ laguage dialcet to GNU++14, C++ standard library to C++11 support and used compiler is Apple LLVM 8.1.

Aucun commentaire:

Enregistrer un commentaire