Boost logo

Boost :

Subject: Re: [boost] Workaround for compiler bugs
From: Edward Diener (eldiener_at_[hidden])
Date: 2010-12-06 19:04:27


On 12/6/2010 5:00 PM, Stephan T. Lavavej wrote:
> [Edward Diener]
>> https://connect.microsoft.com/VisualStudio/feedback/details/624757/incorrect-function-template-deduction-involving-pointor-to-member-data
>
> Is this sufficient for your purposes? (Requires VC10.)
>
> C:\Temp>type meow.cpp
> #include<type_traits>
>
> #define DEFINE_HAS_MEMBER(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; \
> };

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. Otherwise if you can get it to work in VC++, I
would be most appreciative, although I do not know if I want to use the
C++0x 'decltype' feature since the library theoretically needs to work
with C++03 standard compliant compilers.

>
> DEFINE_HAS_MEMBER(cMem)
>
> struct Gipf { };
>
> struct Dvonn {
> Gipf cMem;
> };
>
> struct Tzaar {
> bool cMem;
> };
>
> struct Yinsh {
> int Zertz;
> };
>
> int main() {
> static_assert(has_member_cMem<Dvonn>::value, "Dvonn");
> static_assert(has_member_cMem<Tzaar>::value, "Tzaar");
> static_assert(!has_member_cMem<Yinsh>::value, "Yinsh");
> }
>
> C:\Temp>cl /EHsc /nologo /W4 meow.cpp
> meow.cpp
>
> C:\Temp>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk