I'm trying to use the following construct to check for the existence of a member function based on this answer that I previously got:
template <typename T, class = double>
struct has_a : std::false_type {};
template <typename T>
struct has_a<T, decltype(std::declval<T>().a())> : std::true_type {};
This works fine with gcc 4.9.2, but fails to compile with msvc2013:
error C2228: left of '.a' must have class/struct/union type is 'add_rvalue_reference<_Ty>::type'
It seems(?) like this is a compiler bug, since declval
is specifically supposed to work within an unevaluated decltype
expression (see here). Is there a known workaround?