Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is no std::copy_if algorithm?

Tags:

c++

algorithm

stl

Is there any specific reason for not having std::copy_if algorithm in C++ ? I know I can use std::remove_copy_if to achieve the required behavior. I think it is coming in C++0x, but a simple copy_if which takes a range, a output iterator and a functor would have been nice. Was it just simply missed out or is there some other reason behind it?

like image 561
Naveen Avatar asked Sep 19 '09 15:09

Naveen


2 Answers

According to Stroustrup's "The C++ Programming Language" it was just an over-sight.

(as a citation, the same question answered in boost mail-lists: copy_if)

like image 74
sbk Avatar answered Sep 22 '22 07:09

sbk


Stroustrup says they forgot it. It's in C++11.

However, you can use remove_copy_if (which really should be called copy_if_not) along with not1 instead.

like image 23
rlbond Avatar answered Sep 20 '22 07:09

rlbond