It's very annoying that copy_if
is not in C++. Does anyone know if it will be in C++0x?
views:
405answers:
2
+7
A:
Since the C++0x is not yet finalized, you can only take a look at the most recent draft.
Burkhard
2009-04-27 16:55:10
Sweet raptor Jesus, there it is.
rlbond
2009-04-27 17:05:14
By now, C++0x is pretty well finalized, and the most recent draft is darn close to what the final version will be.
David Thornley
2009-04-27 17:12:07
I agree, I was just reading that gcc 4.4 already has some support for the draft.
Dana the Sane
2009-04-27 17:29:23
+2
A:
In the meantime, it's not very hard to make your own copy_if()
using remove_copy_if()
:
#include <functional>
struct my_predicate : std::unary_function<my_arg_type, bool> {
bool operator()(my_arg_type const& x) const { ... }
};
// To perform "copy_if(x, y, z, my_predicate())", write:
remove_copy_if(x, y, z, std::not1(my_predicate()));
Using not1()
requires your predicate class to supply a nested type, argument_type
, identifying the type of the argument -- as shown above, one convenient way to do this is to derive from unary_function<T, U>
, where T
is the argument type.
j_random_hacker
2009-04-28 10:24:29