00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(AFX_COMPACTSET_H__2FF1D321_9C17_4F6D_A8D4_E1CA4628DB71__INCLUDED_)
00012 #define AFX_COMPACTSET_H__2FF1D321_9C17_4F6D_A8D4_E1CA4628DB71__INCLUDED_
00013
00014 #if _MSC_VER > 1000
00015 #pragma once
00016 #endif // _MSC_VER > 1000
00017
00018 #include "CompactColl.h"
00019 #include <set>
00020
00021
00022 template <class T, class P,class POL, class A>
00023 struct CSetCT
00024 {
00025 typedef T key_type;
00026 typedef T value_type;
00027 typedef T AssignableValueType;
00028 typedef P key_compare;
00029 typedef P value_compare;
00030 typedef A allocator_type;
00031 typedef typename allocator_type::size_type size_type;
00032 typedef POL PolicyTagType;
00033
00034 typedef allocator_type AssignableAllocatorType;
00035 typedef std::set<T,P,A> DynSetType;
00036
00037 key_compare kc;
00038 allocator_type al;
00039 CSetCT(const key_compare& pred,
00040 const allocator_type& alloc)
00041 : kc(pred), al(alloc)
00042 { }
00043 CSetCT()
00044 { }
00045
00046 bool less(const key_type& lhs, const key_type& rhs) const
00047 {
00048 return kc(lhs,rhs);
00049 }
00050 void assign(value_type& lhs, const value_type& rhs) const
00051 {
00052 lhs = rhs;
00053 }
00054 const key_type& extractKey(const value_type& val) const
00055 {
00056 return val;
00057 }
00058 key_type& extractKey(value_type& val) const
00059 {
00060 return val;
00061 }
00062 const key_compare& key_comp() const
00063 {
00064 return kc;
00065 }
00066 const value_compare& value_comp() const
00067 {
00068 return kc;
00069 }
00070 const allocator_type& get_allocator() const
00071 {
00072 return al;
00073 }
00074 };
00075
00076
00077 template<class T,class P = std::less<T>,class POLICY = MaximizeSpeedPolicy,class A = std::allocator<T> >
00078 class CompactSet
00079 : public CompactColl<CSetCT<T,P,POLICY,A> >
00080 {
00081 typedef CompactColl<CSetCT<T,P,POLICY,A> > ImplType;
00082 public:
00083 typedef T key_type;
00084 typedef T value_type;
00085 typedef P key_compare;
00086 typedef P value_compare;
00087 typedef A allocator_type;
00088 typedef typename allocator_type::size_type size_type;
00089 typedef typename allocator_type::difference_type difference_type;
00090
00091 typedef typename ImplType::iterator iterator;
00092 typedef typename ImplType::const_iterator const_iterator;
00093 typedef typename ImplType::reverse_iterator reverse_iterator;
00094 typedef typename ImplType::const_reverse_iterator const_reverse_iterator;
00095
00096 explicit CompactSet(const key_compare& pred = key_compare(),
00097 const allocator_type& alloc = allocator_type())
00098 : ImplType(CSetCT<T,P,POLICY,A>(pred,alloc))
00099 {
00100 }
00101 };
00102
00103 template<class T,class P,class POLICY,class A>
00104 inline bool operator==(const CompactSet<T,P,POLICY,A>& lhs, const CompactSet<T,P,POLICY,A>& rhs)
00105 {
00106 return (lhs.size() == rhs.size()
00107 && std::equal(lhs.begin(),lhs.end(),rhs.begin()));
00108 }
00109
00110 template<class T,class P,class POLICY,class A>
00111 inline bool operator!=(const CompactSet<T,P,POLICY,A>& lhs, const CompactSet<T,P,POLICY,A>& rhs)
00112 {
00113 return ! (lhs == rhs);
00114 }
00115
00116 template<class T,class P,class POLICY,class A>
00117 inline bool operator<(const CompactSet<T,P,POLICY,A>& lhs, const CompactSet<T,P,POLICY,A>& rhs)
00118 {
00119 return std::lexicographical_compare(lhs.begin(),lhs.end(),rhs.begin(),rhs.end());
00120 }
00121
00122 template<class T,class P,class POLICY,class A>
00123 inline bool operator>(const CompactSet<T,P,POLICY,A>& lhs, const CompactSet<T,P,POLICY,A>& rhs)
00124 {
00125 return rhs < lhs;
00126 }
00127
00128 template<class T,class P,class POLICY,class A>
00129 inline bool operator<=(const CompactSet<T,P,POLICY,A>& lhs, const CompactSet<T,P,POLICY,A>& rhs)
00130 {
00131 return ! (rhs < lhs);
00132 }
00133
00134 template<class T,class P,class POLICY,class A>
00135 inline bool operator>=(const CompactSet<T,P,POLICY,A>& lhs, const CompactSet<T,P,POLICY,A>& rhs)
00136 {
00137 return ! (lhs < rhs);
00138 }
00139
00140 #ifndef _MSC_VER
00141 namespace std
00142 {
00143
00144 template<class T,class P,class POLICY,class A>
00145 inline void swap(::CompactSet<T,P,POLICY,A>& lhs, ::CompactSet<T,P,POLICY,A>& rhs)
00146 {
00147 std::cout << "std::swap\n";
00148 lhs.swap(rhs);
00149 }
00150 }
00151 #endif
00152
00153 #endif // !defined(AFX_COMPACTSET_H__2FF1D321_9C17_4F6D_A8D4_E1CA4628DB71__INCLUDED_)
00154 std::cout << "std::swap\n";
00155 lhs.swap(rhs);
00156 }
00157 }
00158 #endif
00159
00160 #endif // !defined(AFX_COMPACTSET_H__2FF1D321_9C17_4F6D_A8D4_E1CA4628DB71__INCLUDED_)