Other operations – HP Integrity NonStop H-Series User Manual
Page 74
![background image](/manuals/396950/74/background.png)
value one. The version of transform() that manipulates two parallel sequences can be used in a similar
fashion.
transform(list_ten.begin(), list_ten.end(),
list_ten.begin(), bind1st(plus
Similarly, the functions replace() and replace_if() (Section 12.4.2) can be used to replace elements of
a list with specific values. Rotations (
Rotate Elements Around a Midpoint
), can also be performed with lists.
// find the location of the value 5, and rotate around it
location = find(list_ten.begin(), list_ten.end(), 5);
rotate(list_ten.begin(), location, list_ten.end());
// now partition using values greater than 7
partition(list_ten.begin(), list_ten.end(),
bind2nd(greater
The functions next_permutation() and prev_permutation() (
) can be used to generate the next permutation (or previous permutation) of a collection of
values.
next_permutation (list_ten.begin(), list_ten.end());
Other Operations
Apply a Function to All Elements...
) will apply a function to every
element of a collection. An illustration of this use will be given in the radix sort example program in
the section on the deque data structure.
The accumulate() generic algorithm reduces a collection to a scalar value (see
). This can be used, for example, to compute the sum of a list of numbers. A
more unusual use of accumulate() will be illustrated in the radix sort example.
cout << "Sum of list is: " <<
accumulate(list_ten.begin(), list_ten.end(), 0) << endl;
Two lists can be compared against each other. They are equal if they are the same size and all
corresponding elements are equal. A list is less than another list if it is lexicographically smaller (see
).