C++ Logo


Advanced search

Should we have std::inplace_transform?

From: Marc Mutz <marc.mutz_at_[hidden]>
Date: Wed, 04 Dec 2019 08:42:57 +0100

I've been telling everyone who (didn't) want to know that std::for_each
is only ever useful for its (very recent) parallelisation capabilities.
That's because for_each is devoid of semantics. What does the thing do?
Does it follow SGI STL rules and just inspects the elements in turn, or
does it take advantage of the leeway that
http://eel.is/c++draft/alg.foreach#2 gave and actually applies an
action to the element? For_each, after all, is still officially a
"non-modifying sequence algorithm", and it's odd that it should be able
to modify elements.

I've also been telling everyone who (didn't) want to know that they can
just write their own inplace_transform, which behaves in all respects
like std::for_each, except for the name.

We can't roll back on http://eel.is/c++draft/alg.foreach#2, but by
providing inplace_transform, we can at least prepare for a future
algorithm vocabulary in which for_each can again no longer modify the



Received on 2019-12-04 01:45:22