|
#include <smart_ptr.hpp>
class automobile { public: automobile(const string &LicPlate):m_LicPlate(LicPlate){} automobile(const automobile& src):m_LicPlate(src.m_LicPlate){} automobile& operator=(const automobile& src){m_LicPlate=src.m_LicPlate;} virtual ~automobile(){} virtual string GetTypeName()const = 0; virtual bool operator<(const automobile& s)const { if (m_LicPlate == s.m_LicPlate) return GetTypeName() < s.GetTypeName(); return m_LicPlate < s.m_LicPlate; } protected: string m_LicPlate; }; class car : public automobile { public: car(const string &LicPlate):automobile(LicPlate){} car(const car& src):automobile(src.m_LicPlate){} car& operator=(const car& src){m_LicPlate=src.m_LicPlate;} string GetTypeName()const{return "car";} }; class truck : public automobile { public: truck(const string &LicPlate):automobile(LicPlate){} truck(const truck& src):automobile(src.m_LicPlate){} truck& operator=(const truck& src){m_LicPlate=src.m_LicPlate;} string GetTypeName()const{return "truck";} }; void example_value_comparsion_semantic_policy_usage() { //value_comparsion_semantic_policy is the default policy //and does not need to be specified explicitly as in the following //example typedef smart_ptr<automobile, ownership_default_policy, allocator_default_policy, checking_default_policy, value_comparsion_semantic_policy> SmrtPtrAutomobile; std::map<SmrtPtrAutomobile, string> mAutomobiles1; mAutomobiles1[new car("1234")] = "IBM"; mAutomobiles1[new truck("8254")] = "MS"; mAutomobiles1[new car("7777")] = "Intel"; mAutomobiles1[new truck("0215")] = "Apple"; std::map<string, SmrtPtrAutomobile > mAutomobiles2; mAutomobiles2["IBM" ] = SmrtPtrAutomobile(new car("1234")) ; mAutomobiles2["MS" ] = SmrtPtrAutomobile(new truck("8254")) ; mAutomobiles2["Intel"] = SmrtPtrAutomobile(new car("7777")) ; mAutomobiles2["Apple"] = SmrtPtrAutomobile(new truck("0215")) ; std::set<SmrtPtrAutomobile > sAutomobiles; sAutomobiles.insert(new car("1234")); sAutomobiles.insert(new truck("8254")); sAutomobiles.insert(new car("7777")); sAutomobiles.insert(new truck("0215")); }
Definition at line 283 of file smart_ptr.hpp.
Static Public Member Functions | |
template<class T1, class T2> | |
static bool | less_than (const T1 &a, const T2 &b) |
template<class T1, class T2> | |
static bool | greater_than (const T1 &a, const T2 &b) |
template<class T1, class T2> | |
static bool | less_than_or_equal (const T1 &a, const T2 &b) |
template<class T1, class T2> | |
static bool | greater_than_or_equal (const T1 &a, const T2 &b) |
template<class T1, class T2> | |
static bool | is_equal (const T1 &a, const T2 &b) |