|
Boost : |
Subject: Re: [boost] Workaround for compiler bugs
From: Stephan T. Lavavej (stl_at_[hidden])
Date: 2010-12-06 17:00:55
[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; \
};
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>
Stephan T. Lavavej
Visual C++ Libraries Developer
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk