设为首页 加入收藏

TOP

STL algorithm算法any_of译文及使用(3)
2015-07-20 17:46:22 来源: 作者: 【 】 浏览:2
Tags:STL algorithm 算法 any_of 译文 使用
?

std::any_of

template 
   
    
  bool any_of (InputIterator first, InputIterator last, UnaryPredicate pred);
   
Test if any element in range fulfills condition Returns true if pred returns true for any of the elements in the range [first,last), and false otherwise.

如果范围内任一元素使pred返回true,则返回true,否则返回false.

例子:

?

#include 
   
    
#include 
    
      using namespace std; bool isGreat(int i){ if(i>=5){ cout<
     
      =5<< ,match!<
      
        vi{0,1,2,3,4,5,6}; if(any_of(vi.begin(),vi.end(),isGreat)) cout<
       
        =5 <
        
         =1 <
         
          运行截图:
          

?

\

If [first,last) is an empty range, the function returns false.

如果范围为空,则返回false.(因为没有任一匹配)

例子:

?

#include 
           
            
#include 
            
              using namespace std; bool isGreat(int i){ if(i>=5){ cout<
             
              =5<< ,match!<
              
                vi{0,1,2,3,4,5,6}; if(any_of(vi.begin(),vi.begin(),isGreat)) cout<
               
                \
                

?

The behavior of this function template is equivalent to:

?

?
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Binary Tree Preorder Traversal 下一篇Character Streams

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C语言中如何将结构体 (2025-12-24 22:20:09)
·纯C语言结构体成员变 (2025-12-24 22:20:06)
·C语言中,指针函数和 (2025-12-24 22:20:03)
·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)