[lambda] Using a reference in an expression
How does one use a reference in a lambda expression? The documentation
says that "var" does, but it clearly doesn't.
For example this fails to compile because it can't access the copy
constructor:
#include
AMDG On 09/12/2012 12:14 PM, Bill Buklis wrote:
How does one use a reference in a lambda expression? The documentation says that "var" does, but it clearly doesn't.
var does work. The argument to operator<< is passed by reference correctly. The error is that the return type is deduced as sample instead of sample&. Try wrapping the expression in bll::ret or look up how to specify the return type in the docs. I don't remember off the top of my head what you need to specialize.
For example this fails to compile because it can't access the copy constructor:
#include
namespace bll = boost::lambda; class sample { public: sample() { } sample& operator<<( int ) { return(*this); }
private: sample( const sample& ); };
void test() { typedef std::vector<int> V;
V v; sample s;
std::for_each(v.begin(), v.end(), bll::var(s) << bll::_1); };
In Christ, Steven Watanabe
On 9/12/2012 11:07 PM, Steven Watanabe wrote:
AMDG
On 09/12/2012 12:14 PM, Bill Buklis wrote:
How does one use a reference in a lambda expression? The documentation says that "var" does, but it clearly doesn't.
var does work. The argument to operator<< is passed by reference correctly. The error is that the return type is deduced as sample instead of sample&. Try wrapping the expression in bll::ret or look up how to specify the return type in the docs. I don't remember off the top of my head what you need to specialize.
Thanks. bll::ret did the trick. I knew I had to be missing something. It didn't occur to me that it was trying to copy the object *after* the expression. -- Bill
participants (2)
-
Bill Buklis
-
Steven Watanabe