home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C21 / Binder2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  948 b   |  36 lines

  1. //: C21:Binder2.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // More binders
  7. #include <algorithm>
  8. #include <vector>
  9. #include <string>
  10. #include <iostream>
  11. #include <functional>
  12. using namespace std;
  13.  
  14. int main() {
  15.   ostream_iterator<string> out(cout, " ");
  16.   vector<string> v, r;
  17.   v.push_back("Hi");
  18.   v.push_back("Hi");
  19.   v.push_back("Hey");
  20.   v.push_back("Hee");
  21.   v.push_back("Hi");
  22.   copy(v.begin(), v.end(), out);
  23.   cout << endl;
  24.   // Replace each "Hi" with "Ho":
  25.   replace_copy_if(v.begin(), v.end(), 
  26.     back_inserter(r), 
  27.     bind2nd(equal_to<string>(), "Hi"), "Ho");
  28.   copy(r.begin(), r.end(), out);
  29.   cout << endl;
  30.   // Replace anything that's not "Hi" with "Ho":
  31.   replace_if(v.begin(), v.end(), 
  32.     not1(bind2nd(equal_to<string>(),"Hi")),"Ho");
  33.   copy(v.begin(), v.end(), out);
  34.   cout << endl;
  35. } ///:~
  36.