Translations of this page?:

replace

#include <algorithm>
 
template< class ForwardIterator, class T >
void replace( ForwardIterator first, ForwardIterator last,
              const T& old_value, const T& new_value );

Replaces all elements with value old_value to value new_value in the range defined by [first, last).

Parameters

first, last - the range of the elements to be processed

old_value - value of the elements to be replaced

new_value - value to be replaced with

Return value

(none)

Equivalent function

template<class ForwardIterator, class T>
void replace(ForwardIterator first, ForwardIterator last,
             const T& old_value, const T& new_value)
{
    for (; first != last; ++first) {
        if (*first == old_value) {
            *first = new_value;
        }
    }
}

Complexity

linear in the distance between first and last

See also

 
• • • SitemapRecent changesRSScc