Boost logo

Boost :

Subject: Re: [boost] [iterator] function_output_iterator constructed from a lambda function is not assignable
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2016-02-15 15:35:34


On 2016-02-14 22:42, Mikhail Matrosov wrote:
> Consider the following code snippet:
>
> auto f = [](int x) { std::cout << x; };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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk