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

  1. //: C21:Binder4.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. // The bound argument does not have 
  7. // to be a compile-time constant
  8. #include "copy_if.h"
  9. #include "PrintSequence.h"
  10. #include "../require.h"
  11. #include <iostream>
  12. #include <algorithm>
  13. #include <functional>
  14. #include <cstdlib>
  15. using namespace std;
  16.  
  17. int boundedRand() { return rand() % 100; }
  18.  
  19. int main(int argc, char* argv[]) {
  20.   requireArgs(argc, 1, "usage: Binder4 int");
  21.   const int sz = 20;
  22.   int a[20], b[20] = {0};
  23.   generate(a, a + sz, boundedRand);
  24.   int* end = copy_if(a, a + sz, b, 
  25.     bind2nd(greater<int>(), atoi(argv[1])));
  26.   // Sort for easier viewing:
  27.   sort(a, a + sz);
  28.   sort(b, end);
  29.   print(a, a + sz, "array a", " ");
  30.   print(b, end, "values greater than yours"," ");
  31. } ///:~
  32.