On Monday, February 15, 2016 at 2:36:02 PM UTC-6, Andrey Semashev wrote:
On 2016-02-14 22:42, Mikhail Matrosov wrote:
Consider the following code snippet:
auto f = ;auto it = boost::make_function_output_iterator(f);decltype(it) it2 = it; // Ok, copied it2 = it; // Does not compile, cannot assign!
Since the lambda does not capture anything, you might try to convert it to a function pointer, which would make it assignable.
typedef void (*lambda_t)(int); auto it = make_function_output_iterator((lambda_t)f);
If you do have to capture variables, you might want to use std::bind to store the captures and a pointer to the lambda function without captures. Or just use std::bind with a normal function.
That is another way. Its simpler just to append a `+` to do that though: auto it = make_function_output_iterator(+[](int x) { std::cout << x; }); Paul