are they adding copy_if to c++0x?

后端 未结 3 1051
一整个雨季
一整个雨季 2021-01-02 18:27

It\'s very annoying that copy_if is not in C++. Does anyone know if it will be in C++0x?

3条回答
  •  情歌与酒
    2021-01-02 18:56

    In the meantime, it's not very hard to make your own copy_if() using remove_copy_if():

    #include 
    
    struct my_predicate : std::unary_function {
        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, where T is the argument type.

提交回复
热议问题