??????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???????????????