fill and fill_n

The fill function is used to fill a container with elements, while the fill_n function is used to fill in the next n elements. For both of the functions, the element that is used as a "filling element" is passed as a parameter when the function is called.

void fill( start_iterator, end_iterator, fill_value );

void fill_n( start_iterator, num_elements_to_fill, fill_value );


generate and generate_n

The generate and generate_n functions are used to generate elements and fill a sequence between a set of iterators (generate) or from a starting point through the next n elements (generate_n). The values that are used to fill a sequence are created by a function that return the appropriate type of values and takes no arguments.

void generate( start_iterator, end_iterator, function_that_generates_values );

void generate_n( start_iterator, num_elements_to_fill, function_that_generates_values );


find, find_if, find_end, and find_first_of

find searches for a specified value within a range specified by 2 iterators. If the value is found, an iterator that refers to the found value is returned. If the value is not found, an iterator that refers to the "end" of the range is returned.

iterator find( start_iterator, end_iterator, search_value );

find_if searches within a specified range for the first element that meets a specified criteria. If a value is found, an iterator that refers to the found value is returned. If the value is not found, an iterator to the "end" of the range is returned.

iterator find_if( start_iterator, end_iterator, boolean_function_that_takes_one_argument );

find_end searches within a specified range for the last occurrence of values within another range. If a matching set of values is found, an iterator that refers to the beginning of the set is returned. If a matching set of values is not found, an iterator to the "end" of the searched range is returned. There are two formats for this function: in the first format, the elements are compared for equality; in the second format, the comparison criteria is specified by a boolean function that compares two elements.

iterator find_end( start_iterator1, end_iterator1, start_iterator2, end_iterator2 );

iterator find_end( start_iterator1, end_iterator1, start_iterator2, end_iterator2, boolean_function_that_takes_two_arguments );

find_first_of searches within a specified range for the first occurrence of a matching value from within another range. If a matching value is found, an iterator that refers to the found value is returned. If a matching value is not found, an iterator to the "end" of the searched range is returned. There are two formats for this function: in the first format, the elements are compared for equality; in the second format, the comparison criteria is specified by a boolean function that compares two elements.

iterator find_first_of( start_iterator1, end_iterator1, start_iterator2, end_iterator2 );

iterator find_first_of( start_iterator1, end_iterator1, start_iterator2, end_iterator2, boolean_function_that_takes_two_arguments );


remove, remove_if, remove_copy, and remove_copy_if

The remove function removes every occurrence of a specified value from within a range specified by 2 iterators. An iterator that refers to the position after the last element of the new range of elements is returned. The size of the container is not modified. The remaining values in the container are shifted to the beginning of the container, however the "vacated" spots will still contain their values.

The remove_if function removes every element within a specified range that meets a specified criteria. An iterator that refers to the position after the last element of the new range of elements is returned. The size of the container is not modified. The remaining values in the container are shifted to the beginning of the container, however the "vacated" spots will still contain their values.

iterator remove( start_iterator, end_iterator, value_to_be_removed );

iterator remove_if( start_iterator, end_iterator, boolean_function_that_takes_one_argument );

The remove_copy function copies all of the elements from within a specified range except for those that match a specified value into a sequence that starts at another position. An iterator that refers to the position after the last element of the new range of elements is returned.

The remove_copy_if function copies all of the elements from within a specified range except for those that meet a specified criteria into a sequence that starts at another position. An iterator that refers to the position after the last element of the new range of elements is returned.

iterator remove_copy( start_iterator1, end_iterator1, start_iterator2, value_to_be_removed );

iterator remove_copy_if( start_iterator1, end_iterator1, start_iterator2, boolean_function_that_takes_one_argument );


replace, replace_if, replace_copy, and replace_copy_if

The replace function replaces every occurrence of a specified value from within a specified range by a new value.

The replace_if function replaces every element within a specified range that meets a specified criteria with a new value.

void replace( start_iterator, end_iterator, value_to_be_replaced, new_value );

void replace_if( start_iterator, end_iterator, boolean_function_that_takes_one_argument, new_value );

The replace_copy function copies all of the elements from within a specified range into a container starting at specified position. Within the copied values, every occurrence of a specified value is replaced by a new value.

The replace_copy_if function copies all of the elements from within a specified range into a container starting at a specified position. Within the copied values, every element that meets a specified criteria is replaced by a new value.

void replace_copy( start_iterator1, end_iterator1, start_iterator2, value_to_be_replaced, new_value );

void replace_copy_if( start_iterator1, end_iterator1, start_iterator2, boolean_function_that_takes_one_argument, new_value );


swap, iter_swap, and swap_ranges

The swap function swaps two values.

void swap( object1, object2 );

The iter_swap function swaps the values at two iterator positions.

void iter_swap( iterator1, iterator2 );

The swap_ranges function swaps the values from within a specified range with values from within a second range. It returns an iterator that refers to the "end" of the second range.

iterator swap_ranges( start_iterator1, end_iterator1, start_iterator2 );


search, search_n, sort, and binary_search

The search function is equivalent to the find_end function but it searches for the first occurrence of a set of values. If a matching set of values is found, an iterator that refers to the beginning of the set is returned. If a matching set of values is not found, an iterator to the "end" of the searched range is returned. There are two formats for this function: in the first format, the elements are compared for equality; in the second format, the comparison criteria is specified by a boolean function that compares two elements.

iterator search( start_iterator1, end_iterator1, start_iterator2, end_iterator2 );

iterator search( start_iterator1, end_iterator1, start_iterator2, end_iterator2, boolean_function_that_takes_two_arguments );

The search_n function searches for the first occurrence of n consecutive occurrences of a specified value within a specified range. If a matching set of values is found, an iterator that refers to the beginning of the set is returned. If a matching set of values is not found, an iterator to the "end" of the searched range is returned. There are two formats for this function: in the first format, the elements are compared for equality; in the second format, the comparison criteria is specified by a boolean function that compares an element in the range with the specified value.

iterator search_n( start_iterator, end_iterator, number_of_consecutive_values, search_value );

iterator search_n( start_iterator, end_iterator, number_of_consecutive_values, search_value, boolean_function_that_takes_two_arguments );

The sort function sorts the elements within a specified range. There are two formats for this function: in the first format, the elements are sorted in ascending order; in the second format, the sort criteria is specified.

void sort( start_iterator, end_iterator );

void sort( start_iterator, end_iterator, sort_criteria );

The binary_search function locates an occurrence of a specified value within a specified range using a binary search. It returns true if the value is found, otherwise it returns false. There are two formats for this function: in the first format, the elements are tested for equalityr; in the second format, the comparison criteria is specified.

bool binary_search( start_iterator, end_iterator, search_value );

bool binary_search( start_iterator, end_iterator, search_value, comparison_criteria );