“过滤器” C ++中的高阶函数 [英] "filter" higher order function in C++
问题描述
C ++标准库和/或Boost有什么类似于函数式语言中的过滤器
函数吗?
Does C++ standard library and/or Boost have anything similar to the filter
function found in functional languages?
我能找到的最接近的函数是 std :: remove_copy_if
,但它似乎正在做我想要的相反。 boost :: lambda
有任何函数来获得我的谓词的否定版本(类似于不是
在Haskell)?我可以否定我的谓词,然后使用 std :: remove_copy_if
。
The closest function I could find was std::remove_copy_if
but it seems to be doing the opposite of what I want. Does boost::lambda
have any function to get a negated version of my predicate (similar to not
in Haskell)? I could negate my predicate and use it with std::remove_copy_if
then.
请注意,如何在C ++中编写 filter
函数;我只是问标准库和/或Boost是否已经提供这样的函数。
Please note that I am not asking how to write filter
function in C++; I am just asking whether standard library and/or Boost already provide such a function.
提前感谢。
推荐答案
包括< functional>
for std :: not1
code> cont.erase(std :: remove_if(cont.begin(),cont.end(),std :: not1(pred())),cont.end());
Include <functional>
for std::not1
and try cont.erase (std::remove_if (cont.begin (), cont.end (), std::not1 (pred ())), cont.end ());
这篇关于“过滤器” C ++中的高阶函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!