My question is partially motivated by this question.
Is there a way to compose STL algorithms, or user made algorithms, without an intermediate container? An answer can use a tool from boost, but assume the composed algorithms are user made, or from the STL.
So boost::adaptors::reversed
doesn't count since the reversing algorithm is in boost.
No.
Let's say f
and g
are STL algorithms.
Let's say what you want is f(g(x))
(I'm trying to convey the idea here...).
There is no way to get around having a intermediate container, since the result of g(x)
must be a container.
If you are going to avoid intermediate containers, then you must use algorithms that can "inspect" or interact with other algorithms, like Boost.Range adaptors
(e.g. boost::adaptors::reversed
).
For example, say f
is "sort" and g
is "reverse". Boost's adapters could figure out that the reverse step is a no-op and skip it. STL algorithms couldn't do that, since there's no way for that information to make it through.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With