home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C19 / applyMember.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1001 b   |  41 lines

  1. //: C19:applyMember.h
  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. // applySequence.h modified to use 
  7. // member function templates
  8.  
  9. template<class T, template<typename> class Seq>
  10. class SequenceWithApply : public Seq<T*> {
  11. public:
  12.   // 0 arguments, any type of return value:
  13.   template<class R>
  14.   void apply(R (T::*f)()) {
  15.     iterator it = begin();
  16.     while(it != end()) {
  17.       ((*it)->*f)();
  18.       it++;
  19.     }
  20.   }
  21.   // 1 argument, any type of return value:
  22.   template<class R, class A>
  23.   void apply(R(T::*f)(A), A a) {
  24.     iterator it = begin();
  25.     while(it != end()) {
  26.       ((*it)->*f)(a);
  27.       it++;
  28.     }
  29.   }
  30.   // 2 arguments, any type of return value:
  31.   template<class R, class A1, class A2>
  32.   void apply(R(T::*f)(A1, A2), 
  33.     A1 a1, A2 a2) {
  34.     iterator it = begin();
  35.     while(it != end()) {
  36.       ((*it)->*f)(a1, a2);
  37.       it++;
  38.     }
  39.   }
  40. }; ///:~
  41.