Boost
C++ Libraries
...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
This is an older version of Boost and was released in 2021. The current version is 1.89.0.
Replaces each element of a given sequence for which an unary function
object evaluates to true
replaced with a new value.
template<
typename Sequence,
typename F,
typename T>
typename result_of::replace_if<Sequence const, F, T>::type replace_if(
Sequence const& seq, F f, T const& new_value);
Table 1.71. Parameters
|
Parameter |
Requirement |
Description |
|---|---|---|
|
|
A model of Forward Sequence |
Operation's argument |
|
|
A function object for which |
Operation's argument |
|
|
Any type |
Replacement value |
replace_if(seq, f, new_value);
Return type: A model of Forward Sequence.
Semantics: Returns a new sequence with
all the elements of seq,
with new_value assigned
to each element for which f
evaluates to true.
Constant. Returns a view which is lazily evaluated.
#include <boost/fusion/algorithm/transformation/replace_if.hpp> #include <boost/fusion/include/replace_if.hpp>
struct odd { template<typename T> bool operator()(T t) const { return t % 2; } }; ... assert(replace_if(make_vector(1,2), odd(), 3) ==make_vector(3,2));