I
Isti
consider the following code:
--------------------------------
#include <iostream>
template<class T> struct always_void { typedef void type; };
template<class T, class Enable = void>
struct has_foo : public std::false_type {};
template<class T>
struct has_foo<T, typename always_void<decltype(&T::foo)>::type>
: public std::true_type {};
struct F {
void foo() {}
};
int main(int argc, char* argv[])
{
std::cout << has_foo<F>::value << std::endl;
std::cout << has_foo<int>::value << std::endl;
return 0;
}
----------------------------------------------------
I expect has_foo<F>::value to be true when F::foo is well-formed and
false otherwise, but when I compiled this with VS 2010 has_foo<F>
turned out to be always false.
When I changed decltype(&T::foo) to decltype(1): has_foo<T> became
always true (independently from T), as expected, so the basic concept
seems to work.
Is it a bug of VS 2010 or am I wrong somewhere?
Thx in advance:
Istvan Kispal
--------------------------------
#include <iostream>
template<class T> struct always_void { typedef void type; };
template<class T, class Enable = void>
struct has_foo : public std::false_type {};
template<class T>
struct has_foo<T, typename always_void<decltype(&T::foo)>::type>
: public std::true_type {};
struct F {
void foo() {}
};
int main(int argc, char* argv[])
{
std::cout << has_foo<F>::value << std::endl;
std::cout << has_foo<int>::value << std::endl;
return 0;
}
----------------------------------------------------
I expect has_foo<F>::value to be true when F::foo is well-formed and
false otherwise, but when I compiled this with VS 2010 has_foo<F>
turned out to be always false.
When I changed decltype(&T::foo) to decltype(1): has_foo<T> became
always true (independently from T), as expected, so the basic concept
seems to work.
Is it a bug of VS 2010 or am I wrong somewhere?
Thx in advance:
Istvan Kispal