& decltype (obj) :: member does not work

Why does this not work (Visual C ++ 2012 Update 1) and what is its correct way?

#include <boost/lambda/bind.hpp> namespace bll = boost::lambda; struct Adder { int m; Adder(int m = 0) : m(m) { } int foo(int n) const { return m + n; } }; #define bindm(obj, f, ...) bind(&decltype(obj)::f, obj, __VA_ARGS__) int main() { return bll::bindm(Adder(5), foo, bll::_1)(5); } 
+4
source share
2 answers

decltype as a decltype specifier was added in C ++ 11 at a relatively late stage; n3049 as a resolution of DR 743 (and DR 950 ). n3049 was published in March 2010, so probably it has not yet found its way into VC ++.

The workaround is to use a function like identity:

 template<typename T> using id = T; id<decltype(expression)>::member; 
+6
source

Compiler error.

Decltype specifier specifier (7.1.6.2 Simple type specifiers [dcl.type.simple]) are explicitly resolved as a speficier nested name (5.1 Primary expressions [expr.prim] → 5.1.1 General expr.prim.general] # 8)

PS. Following @ecatmur's idea:

 template<typename T> struct id { typedef T type; }; #define bindm(obj, f, ...) bind(&id<decltype(obj)>::type::f, obj, __VA_ARGS__) 
+3
source

All Articles