beautypg.com

Other generic algorithms – HP Integrity NonStop H-Series User Manual

Page 90

background image

while the merge will contain five. To form the merge, the function merge() can be used (see

Chapter 14:

Merge Ordered Sequences

). The arguments to this function exactly match those of the

set_union() function.

Set Difference

There are two forms of set difference. A simple set difference represents the elements in the first set
that are not contained in the second. A symmetric set difference is the union of the elements in the
first set that are not contained in the second, with the elements in the second that are not contained
in the first. These two values are constructed by the functions set_difference() and
set_symmetric_difference(), respectively. The use of these functions is similar to the use of the
set_union() function described earlier.

Other Generic Algorithms

Because sets are ordered and have constant iterators, a number of the generic functions described in
Chapters

13

and

14

either are not applicable to sets or are not particularly useful. However, the

following table gives a few of the functions that can be used in conjunction with the

set

data type.

Purpose

Name

Chapter / Section

Copy one sequence into another

copy

13 (

Copy One Sequence into Another

Sequence

)

Find an element that matches a condition

find_if

13 (

Find an Element Satisfying a

Condition

)

Find a subsequence within a set

search

13 (

Find a Subsequence within a Sequence

)

Count number of elements that satisfy
condition

count_if

13 (

Count the Number of Elements...

)

Reduce set to a single value

accumulate

13 (

Reduce Sequence to a Single Value

)

Execute function on each element

for_each

13 (

Apply a Function to All Elements in a

Collection

)

This manual is related to the following products: