STL algorithmアルゴリズムany_of翻訳文及び使用(3)


原文の住所:http://www.cplusplus.com/reference/algorithm/any_前/
function template
<algorithm>
std::any_保存先
template <class InputIterator, class UnaryPredicate>
  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 elemens in the range  [first,last)、and  false others wise.
範囲内のいずれかの要素がpredをtrueに戻すと、trueに戻ります.そうでなければfalseに戻ります.
例:
#include <iostream>
#include <algorithm>
using namespace std;
bool isGreat(int i){
	if(i>=5){
		cout<<i<<">=5"<<" ,match!"<<endl;
		return true;
	}
	else{
		cout<<i<<"<5"<<" ,mismatch!"<<endl;
		return false;
	}
}
int main()
{
	vector<int> vi{0,1,2,3,4,5,6};
	if(any_of(vi.begin(),vi.end(),isGreat))
		cout<<"Yes,some elements in vi  >=5 "<<endl;
	else
		cout<<"no,all elements in vi didn't >=1 "<<endl;


	cout<<endl;
	int ar[5]={10,20,30,40,50};
	if(any_of(ar,ar+5,[](int i){return i%10;}))
		cout<<"some in ar can %10!=0"<<endl;
	else
		cout<<"all %10=0!"<<endl;


}
はスクリーンショットを実行します.
STL algorithm算法any_of译文及使用(3)_第1张图片
If.  [first,last) is an empty range,the function returns  false.
範囲が空の場合はfalseを返します.
例:
#include <iostream>
#include <algorithm>
using namespace std;
bool isGreat(int i){
	if(i>=5){
		cout<<i<<">=5"<<" ,match!"<<endl;
		return true;
	}
	else{
		cout<<i<<"<5"<<" ,mismatch!"<<endl;
		return false;
	}
}
int main()
{
	vector<int> vi{0,1,2,3,4,5,6};
	if(any_of(vi.begin(),vi.begin(),isGreat))
		cout<<"emptiy=true "<<endl;
	else
		cout<<"emptiy=false "<<endl;



}
The behavior of this function template is equivalent to:
行為は以下の通りです.
1 2 3 4 5 6 7 8 9 
template<class InputIterator, class UnaryPredicate> bool any_of (InputIterator first, InputIterator last, UnaryPredicate pred) { while (first!=last) { if (pred(*first)) return true; ++first; } return false; }
パラメータ
ファースト
Input iterators トthe initial and final positions in a sequence.The range used is  [first,last),which contains all theelemens between ファースト and last,including the element pointed by ファースト but not the element pointed by last.
シーケンス範囲を示す入力ローズマリー.first、lastの間のすべての要素は、firstが指す要素を含むが、lastは含まれない.
pred
Unary function that accepts an element in the range as argment and returns a value convertible to  bool.The value returned indicates whethe element fulfills the condition checed by this function.The function shel not modify its argment.
This can eigther be a function pointer or a function oject.
要素タイプのパラメータを受け取り、ブール値の一要素関数を返します.
ポインタまたは関数オブジェクトとすることができます.
Return valuetrue if pred returns  true for any of the elemens in the range  [first,last)、and  false others wise.
いずれかの要素のpredに対する戻り値がtrueである場合、trueに戻ります.そうでなければfalseに戻ります.
If.  [first,last) is an empty range,the function returns  false.
範囲が空の場合はfalseを返します.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 
// any_of example #include <iostream> // std::cout #include <algorithm> // std::any_of #include <array> // std::array int main () { std::array<int,7> foo = {0,1,-1,3,-3,5,-5}; if ( std::any_of(foo.begin(), foo.end(), [](int i){return i<0;}) ) std::cout << "There are negative elements in the range.
"; return 0; }
Edit&Run
Output:
There are negative elements in the range. 
Coplexity
Up to linear in the distance between ファースト and last:Calls pred for each element until a match is found.
firstとlastとの間の距離は直線的に相関しており、各要素に対してpredは一致する値まで呼び出される.
Data races
Some(or all)of the object in the range  [first,last) are accessed(once at most)
少なくとも1つの要素がアクセスされます.
Exceptions
Throws if either pred or an operation an iterator throws.
Note that invalid parameters cause undefined behavior.
predまたは操作している場合は、異常を投げます.
無効なパラメータは未定義の挙動をもたらします.
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//書いた間違いや悪いところを教えてください.下のメッセージを残したり、左上のメールアドレスをクリックしてメールしてください.私の間違いと不足を指摘してください.修正して、皆さんにもっといいものを教えてください.ありがとうございます.
転載は出典を明記してください.http://blog.csdn.net/qq844352155
author:天下無双
メール:[email protected]
2014-9-1
GDUTで
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————