// boost.cp #include #include #define BOOST_NMEMBER_TEMPLATES #include "smart_ptr.h" namespace boost { template bool operator<(boost::shared_ptr lhs, boost::shared_ptr rhs) { return *lhs < *rhs; } } typedef int ExpensiveToCopyObject; typedef boost::shared_ptr 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 l; l.push_back(two); l.push_back(four); l.push_back(three); l.push_back(one); l.sort(); std::list::iterator iter; for (iter = l.begin(); iter != l.end(); ++iter) { std::cout << *(*iter) << ' '; } } // line 1 } // line 2 // 1 2 3 4