home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Presentations / STL & Modern C++ / boost.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  754 b   |  44 lines  |  [TEXT/CWIE]

  1. // boost.cp
  2. #include <iostream>
  3. #include <list>
  4.  
  5. #define BOOST_NMEMBER_TEMPLATES
  6. #include "smart_ptr.h"
  7.  
  8. namespace boost
  9. {
  10. template<class T>
  11. bool    operator<(boost::shared_ptr<T> lhs, boost::shared_ptr<T> rhs)
  12. {
  13.     return *lhs < *rhs;
  14. }
  15. }
  16.  
  17. typedef    int ExpensiveToCopyObject;
  18. typedef boost::shared_ptr<ExpensiveToCopyObject>    ObjectPtr;
  19.  
  20. int main()
  21. {
  22.     ObjectPtr    one(new int(1));
  23.     ObjectPtr    two(new int(2));
  24.     ObjectPtr    three(new int(3));
  25.     ObjectPtr    four(new int(4));
  26.  
  27.     {
  28.         std::list<ObjectPtr>    l;
  29.         l.push_back(two);
  30.         l.push_back(four);
  31.         l.push_back(three);
  32.         l.push_back(one);
  33.  
  34.         l.sort();
  35.         std::list<ObjectPtr>::iterator iter;
  36.         for (iter = l.begin(); iter != l.end(); ++iter)
  37.         {
  38.             std::cout << *(*iter) << ' ';
  39.         }
  40.     }    // line 1
  41. }        // line 2
  42.  
  43. // 1 2 3 4
  44.