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

  1. //: C21:PtrFun1.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. // Using ptr_fun() for single-argument functions
  7. #include <algorithm>
  8. #include <vector>
  9. #include <iostream>
  10. #include <functional>
  11. using namespace std;
  12.  
  13. char* n[] = { "01.23", "91.370", "56.661",
  14.   "023.230", "19.959", "1.0", "3.14159" };
  15. const int nsz = sizeof n / sizeof *n;
  16.  
  17. template<typename InputIter>
  18. void print(InputIter first, InputIter last) {
  19.   while(first != last)
  20.     cout << *first++ << "\t";
  21.   cout << endl;
  22. }
  23.  
  24. int main() {
  25.   print(n, n + nsz);
  26.   vector<double> vd;
  27.   transform(n, n + nsz, back_inserter(vd), atof);
  28.   print(vd.begin(), vd.end());
  29.   transform(n,n + nsz,vd.begin(), ptr_fun(atof));
  30.   print(vd.begin(), vd.end());
  31. } ///:~
  32.