He escrito el siguiente código para tratar de detectar si un tipo tiene una variable de miembro estática. Lamentablemente, siempre está volviendo que la variable no existe.sfinae busca miembro estático usando decltype
¿Podría alguien decirme dónde me está yendo mal? Estoy usando g ++ 4.7.1.
#include <iostream>
#include <utility>
#include <type_traits>
using namespace std;
template <class T>
class has_is_baz
{
template<class U,
typename std::enable_if<std::is_same<bool, decltype(U::is_baz)>::value>::type...>
static std::true_type check(int);
template <class>
static std::false_type check(...);
public:
static constexpr bool value = decltype(check<T>(0))::value;
};
struct foo { };
struct bar
{
static constexpr bool is_baz = true;
};
int main()
{
cout << has_is_baz<foo>::value << '\n';
cout << has_is_baz<bar>::value << '\n';
}
Esto no requiere que 'U :: is_baz' sea estático. A 'struct A {bool is_baz; }; 'también funcionará. –
@ JohannesSchaub-litb tienes razón. Parece que funciona ahora. – mfontanini