这似乎像find_if完全一样.
说我有一个函子:function< bool(int)> FOO;
和一个数组:vector< int>酒吧;
看来这两个电话是完全一样的:
any_of(bar.begin(),bar.end(),foo);
和
bar.end() != find_if(bar.begin(),foo);
我进一步感觉,all_of和none_of可以通过否定find_if语句来实现.
解决方法
These three algorithms provide the ordinary mathematical operations ∀,∃,and ∄: given a
range and a predicate,determine whether that predicate is true for all elements; whether
there exists an element for which the predicate is true; or whether there exist no elements
for which the predicate is true. Strictly speaking there is no need to provide all three of
these algorithms (!none_of
andany_of
are equivalent),but all three of these operations
feel equally fundamental.
这些名称比包含find_if和(in)等式的表达更自然,更容易阅读(肯定是非专家C程序员).
all_of(first,last,pred)是return last == std :: find_if_not(first,pred);
none_of(first,pred)是return last == std :: find_if(first,pred);
原文地址:https://www.jb51.cc/c/111960.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。