I'd like to use Boost.Phoenix to create a lambda function that consists of a few lines of code and then "returns" a value so I can use it together with std::transform
.
Like this:
std::transform(a.begin(), a.end(), b.begin(),
(
//Do something complicated here with the elements of a:
statement1,
statement2,
statement3
//Is there a way to return a value here?
)
);
With std::for_each
this would work perfectly, but with std::transform
it does not compile because the comma operator returns void
. How can I return a value from a lambda function like this?
Edit: I changed the code fragment because what I wrote in the first place led to misunderstandings about what I want to do.
No, this isn't possible. From the Boost.Phoenix v2 statement docs:
Unlike lazy functions and lazy operators, lazy statements always return void.
(Note that this same assertion is in the Boost.Phoenix v3 docs as well.)