boost::remove_copy_if
References
Headers
boost::remove_copy_if
is available by including
any of the following headers:
boost/range/algorithm/remove_copy_if.hpp
orboost/range/algorithm.hpp
Examples
remove_copy_if.cpp
#include <functional>
#include <iostream>
#include <vector>
#include <boost/range/algorithm.hpp>
bool is_3_or_4(int i) {
return i == 3 || i == 4;
}
int main() {
std::vector<int> vec = {1, 2, 3, 4, 5};
std::vector<int> output;
// remove_copy_if() wraps std::remove_copy_if(). Elements in the input
// range are copied to the output iterator if they are not filtered by the
// predicate function. The input is not modified.
// Returns an iterator to the end of the output range.
boost::remove_copy_if(vec, std::back_inserter(output), is_3_or_4);
std::cout << "input vector after remove_copy_if(): ";
boost::range::copy(vec, std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
std::cout << "output vector after remove_copy_if(): ";
boost::range::copy(output, std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
return 0;
}
Output:
input vector after remove_copy_if(): 1 2 3 4 5
output vector after remove_copy_if(): 1 2 5
Boost Range for Humans
This reference is part of Boost Range for Humans. Click the link to the overview.