Dmitry J
Dmitry J

Reputation: 927

std::transform unary operation signature

I'm puzzled with the following description of std::transfrom:

unary_op - unary operation function object that will be applied. The signature of the function should be equivalent to the following:

Ret fun(const Type &a);

The signature does not need to have const &.

These two statements seem contradictory. Could someone clarify what is meant here? What happens if signature is Ret fun(Type a) or Ret fun(Type&& a) or Ret fun(Type& a)?

Upvotes: 3

Views: 315

Answers (1)

What it is trying to say, is that fun must be such that:

*OutputIt = fun(*InputIt);

is legal. Note also that

unary_op ... must not invalidate any iterators, including the end iterators, or modify any elements of the ranges involved.

, so a non-const reference would be legal - but it mustn't use the non-constness.

Upvotes: 5

Related Questions