Problemas do compilador SFINAE
O meu código a seguir deve detectar seT
tembegin
eend
métodos:
template <typename T>
struct is_container
{
template <typename U, typename U::const_iterator (U::*)() const,
typename U::const_iterator (U::*)() const>
struct sfinae {};
template <typename U> static char test(sfinae<U, &U::begin, &U::end>*);
template <typename U> static long test(...);
enum { value = (1 == sizeof test<T>(0)) };
};
E aqui está um código de teste:
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
int main()
{
std::cout << is_container<std::vector<std::string> >::value << ' ';
std::cout << is_container<std::list<std::string> >::value << ' ';
std::cout << is_container<std::set<std::string> >::value << ' ';
std::cout << is_container<std::map<std::string, std::string> >::value << '\n';
}
No g ++ 4.5.1, a saída é1 1 1 1
. No Visual Studio 2008, no entanto, a saída é1 1 0 0
. Fiz algo errado ou isso é simplesmente um bug do VS 2008? Alguém pode testar em um compilador diferente? Obrigado!