??????effective STL?????о???棬?????????????д?????????????????????????????????3????STL????????
??????????????????????棺
???????????????????????
???????????????????
????????????????????
???????????????????????????????????????????????????????????????????????汾??
??????????????
????find() ???????????????
????find()??????????в?????????????壺
????template
????InputIterator find (InputIterator first?? InputIterator last?? const T& val);
???????????myvector?в???30??
????int myints[] = { 10?? 20?? 30?? 40 };
????std::vector<int> myvector (myints??myints+4);
????it = find (myvector.begin()?? myvector.end()?? 30);
????if (it != myvector.end())
????std::cout << "Element found in myvector: " << *it << ' ';
????else
????std::cout << "Element not found in myvector ";
????find_if() ??????????
????std::find_if():?????????????????????????????????
???????????myvector?в????????30??????????????
????bool cmpFunction (int i) {
????return ((i%30)==0);
????}
????it = std::find_if (myvector.begin()?? myvector.end()?? cmpFunction);
????std::cout << "first:" <<  *it <<std::endl;
????count() ????????????
????std::count()??????????????????????????
????std:count_if()??count()?????????????汾
????search_n() ??????????????????λ??
????search_n(): find???????????????search_n???????????????????????n?ε?????
????????????myvector??30????????2?ε?λ???
????int myints[]={10??20??30??30??20??10??10??20};
????std::vector myvector (myints??myints+8);
????it = std::search_n (myvector.begin()?? myvector.end()?? 2?? 30);
????search_n() ???????????????
????adjacent_find() ???????????????????λ??
????adjacent_find() ???????????????????λ??????????????????????
????lower_bound() ?????????в???????
????lower_bound()???????????????????в?????????С????????????
?????????????????v?в?С??20????磺
????int myints[] = {10??20??30??30??20??10??10??20};
????std::vector<int> v(myints??myints+8);           // 10 20 30 30 20 10 10 20
????std::sort (v.begin()?? v.end());                // 10 10 10 20 20 20 30 30
????std::vector<int>::iterator low??up;
????low=std::lower_bound (v.begin()?? v.end()?? 20);
????std::cout << "lower_bound at position " << (low- v.begin()) << ' ';
????????????upper_bound()???????????????е??????????????????
????????equal_range()??????????????????±?磻????η???lower_bound()??upper_bound());
????binary_search() ???????????????
????binary_search() ??????????????????????????????????????????????У????????????????bool??
?????????±?λ?????????????????lower_bound???????????????????
????template <class ForwardIterator?? class T>
????bool binary_search (ForwardIterator first?? ForwardIterator last?? const T& val)
????{
????first = std::lower_bound(first??last??val);
????return (first!=last && !(val<*first));
????}
???????????????????v????3???????
????int myints[] = {1??2??3??4??5??4??3??2??1};
????std::vector<int> v(myints??myints+9);                         // 1 2 3 4 5 4 3 2 1
????std::sort (v.begin()?? v.end());
????if (std::binary_search (v.begin()?? v.end()?? 3))
????std::cout << "found! "; else std::cout << "not found. ";
????min_element() ????С???
????min_element() ??????????в????С?;
????int myints[] = {3??7??2??5??6??4??9};
????std::cout << "The smallest element is " << *std::min_element(myints??myints+7) << ' ';
???????????У?max_element() ????????
??????????? search()
????search() ????????????γ????λ??
????find()???????????????search()???????????????????
???????????myvector?в????????????[20??30]??λ??:
????int needle1[] = {20??30};
????it = std::search (myvector.begin()?? myvector.end()?? needle1?? needle1+2);
????if (it!=myvector.end())
????std::cout << "needle1 found at position " << (it-myvector.begin()) << ' ';
????search???????????????
????????????????????????????????????С1????????
????bool cmpFunction (int i?? int j) {
????return (i-j==1);
????}
????int myints[] = {1??2??3??4??5??1??2??3??4??5};
????std::vector haystack (myints??myints+10);
????int needle2[] = {1??2??3};
????// using predicate comparison:
????it = std::search (haystack.begin()?? haystack.end()?? needle2?? needle2+3?? cmpFunction);
????find_end() ?????????????γ????λ??
????search() ?????????????????γ????λ?????find_end()?????????????????γ????λ???
????find_end()???????????????
????equal() ?ж???????????????
????equal?????????ж???????????????????????????????????
????mismatch() ?????????????γ???????λ???
????mismatch() ??????????????????????λ????????????????????????
???????????
????find_first_of ????????е???????????
????find_first_of()????????????????е???????????:
???????????haystack?в???A??B??C?????λ???
????int mychars[] = {'a'??'b'??'c'??'A'??'B'??'C'};
????std::vector haystack (mychars??mychars+6);
????int needle[] = {'C'??'B'??'A'};
????// using default comparison:
????it = find_first_of (haystack.begin()?? haystack.end()?? needle?? needle+3);
????find_first_of???????????????