home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-25 | 754 b | 44 lines | [TEXT/CWIE] |
- // boost.cp
- #include <iostream>
- #include <list>
-
- #define BOOST_NMEMBER_TEMPLATES
- #include "smart_ptr.h"
-
- namespace boost
- {
- template<class T>
- bool operator<(boost::shared_ptr<T> lhs, boost::shared_ptr<T> rhs)
- {
- return *lhs < *rhs;
- }
- }
-
- typedef int ExpensiveToCopyObject;
- typedef boost::shared_ptr<ExpensiveToCopyObject> ObjectPtr;
-
- int main()
- {
- ObjectPtr one(new int(1));
- ObjectPtr two(new int(2));
- ObjectPtr three(new int(3));
- ObjectPtr four(new int(4));
-
- {
- std::list<ObjectPtr> l;
- l.push_back(two);
- l.push_back(four);
- l.push_back(three);
- l.push_back(one);
-
- l.sort();
- std::list<ObjectPtr>::iterator iter;
- for (iter = l.begin(); iter != l.end(); ++iter)
- {
- std::cout << *(*iter) << ' ';
- }
- } // line 1
- } // line 2
-
- // 1 2 3 4
-