From the course: C++ Templates and the STL

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

The transform function

The transform function - C++ Tutorial

From the course: C++ Templates and the STL

The transform function

- [Narrator] The transform function is used to run bulk transformations on elements in a container. Here I have a working copy of transform.cpp from chapter four of the exercise files. The transform template function is found in the algorithm header and we'll get back to these template class and functions at the top here in a minute. Take a look at the transform function itself. This version of it takes four arguments. The first is a starting point iterator and its input iterator so it only needs to end forward. The second is also an input iterator for the endpoint of the source container. So these first two are the begin point and the endpoint of this first container, and the third one is the begin point of the destination container and it is of course an output iterator. The fourth argument is an object operator. It's a unary function, so it's a pointer to either a function or a object functor that takes one argument. In this case it's pointing to X. And you see that X is declared…

Contents