Prev: Updated performance tests using Boost Serialization lib
Next: Fast Assignment of POD Struct Whose Members Have Copy Constructors
From: zrb on 12 Dec 2009 16:26 I am aware of the std::function solution... but I was wondering if it is possible to avoid it. auto foo = [](int x){return x+1;}; auto bar = [](int x){return x+1;}; The example given above that mentioned that "foo" is not the same type as "bar" sums up the problem. In fact, when I change the code to... 21 typedef decltype([=]() -> int {return 0;}) getterXType; 22 23 getterXType getterX() 24 { 25 return ([=]() -> int {return this->m_x;}); 26 } ....I get the following error. main.cpp: In member function �<lambda()>& LambdaMember::getterX()�: main.cpp:25:45: error: invalid initialization of non-const reference of type �<lambda()>&� from an rvalue of type �LambdaMember::getterX ()::<lambda()>� This is a type conversion error... despite having the same signature, the two lambda functions are not of the same type, since the one inside "getterX()" is actually a class type local to the function. While I am happy with the std::function approach... does anybody see any potential problems? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Mathias Gaunard on 12 Dec 2009 22:31
On 13 d�c, 09:26, zrb <zraj...(a)gmail.com> wrote: > While I am happy with the std::function approach... does anybody see > any potential problems? Prefer std::nested_function, or whatever its name is, that's better. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |