Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

&decltype(obj)::member not working

Why is does this not work (Visual C++ 2012 Update 1), and what is the proper way to fix it?

#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);
}
like image 491
user541686 Avatar asked Jan 15 '23 19:01

user541686


1 Answers

decltype as a nested-name-specifier was added into C++11 at a relatively late stage; n3049 as the resolution to DR 743 (and DR 950). n3049 was published in March 2010, which is probably why it hasn't found its way into VC++ yet.

The workaround is to use the identity typefunction:

template<typename T> using id = T;
id<decltype(expression)>::member;
like image 199
ecatmur Avatar answered Jan 29 '23 05:01

ecatmur