os_replace_if |
Replaces specified values that satisfy a predicate.
A helper algorithm for replace_if()
. Replaces every element in the container c that
satisfies pred with value .
#include <ospace/helper/regalgo.h>
template< class Container, class Predicate, class T >
void os_replace_if( Container& c, Predicate pred, const T& value )
#include <iostream>
#include <vector>
#include <ospace/helper.h>
bool
odd( int a_ )
{
return a_ % 2;
}
void
main()
{
vector< int > v1( 10 );
for ( size_t i = 0; i < v1.size(); ++i )
{
v1[ i ] = i % 5;
cout << v1[ i ] << ` `;
}
cout << "\n";
os_replace_if( v1, odd, 42 );
for ( i = 0; i < v1.size(); ++i )
cout << v1[ i ] << ` `;
cout << "\n";
}
0 1 2 3 4 0 1 2 3 4
0 42 2 42 4 0 42 2 42 4
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.