While looking at std::copy_if details at here, the 3rd argument is an OutputIterator.
template <class InputIterator, class OutputIterator, class UnaryPredicate>
OutputIterator copy_if (InputIterator first, InputIterator last,
OutputIterator result, UnaryPredicate pred);
I have below code which is using std::back_inserter as the 3rd argument. When i look at std::back_inserter details here , then it doesn't mention it as an OutputIterator.
- Is
OutputIteratorany class OR just a way to indicate any Iterator which can output something? - Is
OutputIteratorrelated to ostream_iterator somehow? - Why its mentioned here that Incrementing the
std::ostream_iteratoris a no-op. What does it mean? Does it mean that we can't do a ++ onstd::ostream_iterator?
int main()
{
std::vector<int> vec {1, 22, 3, 4, 5, 12, 14};
std::vector<int> rvec;
std::copy_if(std::begin(vec), std::end(vec), std::back_inserter(rvec), [](const int& x){ return (x % 2 == 0);})
}