vendredi 22 juillet 2016

template meta programming result changed between gcc-4.9.3 and gcc-4.5

I have a simple test program here which outputs a different result when compiling on gcc-4.9.3 and gcc-5.1

#include <iostream>
#include <map>

template< class... >
using void_t = void;

template<class, class = void_t<>>
struct has_member_type : std::false_type
{ };

template<class T>
struct has_member_type<T, void_t<typename T::type>> : std::true_type
{ };

int main()
{
    std::cout << has_member_type<int>::value << '\n';

    return 0;
}

gcc-4.9.3 output:

1

gcc-5.1 output:

0

I've been unable to find an online compiler which allows me to compile with two different compiler versions.

However, I have found two separate online compilers which have difference compiler versions:

Question:

  • Why does gcc-4.9.3 output 1 when there is clearly no member int::type?

Aucun commentaire:

Enregistrer un commentaire