SFINAE member function existence test issue
c++, sfinae
Solution
That's because these functions returns references, and you are declaring a pointer to the returning value, that is a pointer to a reference, and that is impossible.
The quick fix would be:
template <typename U> static true_type
f(typename remove_reference< decltype(declval<U>().member()) >::type *);
PS: These kind of errors can be (relatively) easy to solve if you force the compiler to give an error when the SFINAE fails and you think it should not.
I mean, in your code, just comment out the `false_type` and see the errors from the compiler when `true_type` is the only option. Between a buch of meaningless lines there is the following:
test.cpp:9:50: error: forming pointer to reference type
‘__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type& {aka int&}’
Problem
I have this member function test: ``` template <typename T> struct has_member { template <typename U> static true_type f(decltype(declval<U>().member()) *); template <typename> static false_type f(...); static const bool value = decltype(f<T>(0))::value; }; ``` It evaluates to true when there exists a member function with a given name, in the case that the function has an overload that takes no arguments. For such functions and in the case of STL containers, it works properly except for elements access functions (front, back etc.), where it invariably evaluates to false. Why is that? I have mingw g++ 4.7.