
On 12/6/2010 7:43 PM, Stephan T. Lavavej wrote:
[Edward Diener]
You missed the fact in the attachment that the T passed in must be the full signature of a pointer to data member, as in 'Gipf Dvonn::*' in your first example below.
I wasn't sure if mentioning the data member's type was a desired feature of your code. Here's how to achieve that:
C:\Temp>type meow.cpp #include<type_traits>
#define DEFINE_HAS_MEMBER_OF_TYPE(NAME) \ template<typename T> class has_member_ ## NAME { \ private: \ template<typename U> static std::true_type helper(decltype(&U::NAME)); \ template<typename U> static std::false_type helper(...); \ public: \ typedef decltype(helper<T>(nullptr)) type; \ static const bool value = type::value; \ }; \ \ template<typename T, typename X, bool B> \ struct has_member_ ## NAME ## _of_type_helper \ : public std::false_type { }; \ \ template<typename T, typename X> \ struct has_member_ ## NAME ## _of_type_helper<T, X, true> \ : public std::is_same<decltype(&T::NAME), X T::*> { }; \ \ template<typename T, typename X> \ struct has_member_ ## NAME ## _of_type \ : public has_member_ ## NAME ## _of_type_helper< \ T, X, has_member_ ## NAME<T>::value> { };
Thanks ! I will look at this and see what I can do with it, but I have to achieve this without the use of 'decltype'. The obvious reason is that 'decltype' is C++0x and I will almost certainly target my library for C++ compilers which support only C++03 instead at the base level of use. Obviously I do not mind using C++0x features as long as a compiler supports them but if they do not, this should still be workable without them. Also, while VC++ 10 supports decltype, VC++ 9 and below does not and I need to get my library working with those earlier versions of VC++ also.