boost::range::remove_if
References
Headers
boost::range::remove_if
is available by including
any of the following headers:
boost/range/algorithm/remove_if.hpp
orboost/range/algorithm.hpp
Examples
remove_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};
// remove_if() is a wrapper for std::remove_if(). Elements in the input
// range are reordered, but the size of the input container is not changed.
// An iterator to the new end is returned.
std::vector<int>::iterator end_it = boost::range::remove_if(vec, is_3_or_4);
std::cout << "input vector after remove_if(): ";
boost::range::copy(vec, std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
std::cout << "Index of the returned iterator: " << (end_it - vec.begin());
std::cout << std::endl;
return 0;
}
Output:
input vector after remove_if(): 1 2 5 4 5
Index of the returned iterator: 3
Boost Range for Humans
This reference is part of Boost Range for Humans. Click the link to the overview.