| 1 | // |
| 2 | // Boost.Pointer Container |
| 3 | // |
| 4 | // Copyright Thorsten Ottosen 2008. Use, modification and |
| 5 | // distribution is subject to the Boost Software License, Version |
| 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // For more information, see http://www.boost.org/libs/ptr_container/ |
| 10 | // |
| 11 | |
| 12 | #ifndef BOOST_PTR_CONTAINER_PTR_UNORDERED_MAP_HPP |
| 13 | #define BOOST_PTR_CONTAINER_PTR_UNORDERED_MAP_HPP |
| 14 | |
| 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
| 16 | # pragma once |
| 17 | #endif |
| 18 | |
| 19 | #include <boost/unordered_map.hpp> |
| 20 | #include <boost/ptr_container/ptr_map_adapter.hpp> |
| 21 | #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> |
| 22 | |
| 23 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) |
| 24 | #pragma GCC diagnostic push |
| 25 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 26 | #endif |
| 27 | |
| 28 | namespace boost |
| 29 | { |
| 30 | |
| 31 | template |
| 32 | < |
| 33 | class Key, |
| 34 | class T, |
| 35 | class Hash = boost::hash<Key>, |
| 36 | class Pred = std::equal_to<Key>, |
| 37 | class CloneAllocator = heap_clone_allocator, |
| 38 | class Allocator = std::allocator< std::pair<const Key, |
| 39 | typename ptr_container_detail::void_ptr<T>::type> > |
| 40 | > |
| 41 | class ptr_unordered_map : |
| 42 | public ptr_map_adapter<T,boost::unordered_map<Key, |
| 43 | typename ptr_container_detail::void_ptr<T>::type,Hash,Pred,Allocator>, |
| 44 | CloneAllocator,false> |
| 45 | { |
| 46 | typedef ptr_map_adapter<T,boost::unordered_map<Key, |
| 47 | typename ptr_container_detail::void_ptr<T>::type,Hash,Pred,Allocator>, |
| 48 | CloneAllocator,false> |
| 49 | base_type; |
| 50 | |
| 51 | typedef ptr_unordered_map<Key,T,Hash,Pred,CloneAllocator,Allocator> this_type; |
| 52 | |
| 53 | public: |
| 54 | typedef typename base_type::size_type size_type; |
| 55 | |
| 56 | private: |
| 57 | using base_type::lower_bound; |
| 58 | using base_type::upper_bound; |
| 59 | using base_type::rbegin; |
| 60 | using base_type::rend; |
| 61 | using base_type::crbegin; |
| 62 | using base_type::crend; |
| 63 | using base_type::key_comp; |
| 64 | using base_type::value_comp; |
| 65 | using base_type::front; |
| 66 | using base_type::back; |
| 67 | |
| 68 | public: |
| 69 | using base_type::begin; |
| 70 | using base_type::end; |
| 71 | using base_type::cbegin; |
| 72 | using base_type::cend; |
| 73 | using base_type::bucket_count; |
| 74 | using base_type::max_bucket_count; |
| 75 | using base_type::bucket_size; |
| 76 | using base_type::bucket; |
| 77 | using base_type::load_factor; |
| 78 | using base_type::max_load_factor; |
| 79 | using base_type::rehash; |
| 80 | using base_type::key_eq; |
| 81 | using base_type::hash_function; |
| 82 | |
| 83 | public: |
| 84 | ptr_unordered_map() |
| 85 | { } |
| 86 | |
| 87 | explicit ptr_unordered_map( size_type n ) |
| 88 | : base_type( n, ptr_container_detail::unordered_associative_container_tag() ) |
| 89 | { } |
| 90 | |
| 91 | ptr_unordered_map( size_type n, |
| 92 | const Hash& comp, |
| 93 | const Pred& pred = Pred(), |
| 94 | const Allocator& a = Allocator() ) |
| 95 | : base_type( n, comp, pred, a ) |
| 96 | { } |
| 97 | |
| 98 | template< typename InputIterator > |
| 99 | ptr_unordered_map( InputIterator first, InputIterator last ) |
| 100 | : base_type( first, last ) |
| 101 | { } |
| 102 | |
| 103 | template< typename InputIterator > |
| 104 | ptr_unordered_map( InputIterator first, InputIterator last, |
| 105 | const Hash& comp, |
| 106 | const Pred& pred = Pred(), |
| 107 | const Allocator& a = Allocator() ) |
| 108 | : base_type( first, last, comp, pred, a ) |
| 109 | { } |
| 110 | |
| 111 | BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_map, |
| 112 | base_type, |
| 113 | this_type ) |
| 114 | |
| 115 | template< class U > |
| 116 | ptr_unordered_map( const ptr_unordered_map<Key,U>& r ) : base_type( r ) |
| 117 | { } |
| 118 | |
| 119 | ptr_unordered_map& operator=( ptr_unordered_map r ) |
| 120 | { |
| 121 | this->swap( r ); |
| 122 | return *this; |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | |
| 127 | |
| 128 | template |
| 129 | < |
| 130 | class Key, |
| 131 | class T, |
| 132 | class Hash = boost::hash<Key>, |
| 133 | class Pred = std::equal_to<Key>, |
| 134 | class CloneAllocator = heap_clone_allocator, |
| 135 | class Allocator = std::allocator< std::pair<const Key,void*> > |
| 136 | > |
| 137 | class ptr_unordered_multimap : |
| 138 | public ptr_multimap_adapter<T,boost::unordered_multimap<Key,void*,Hash,Pred,Allocator>, |
| 139 | CloneAllocator,false> |
| 140 | { |
| 141 | typedef ptr_multimap_adapter<T,boost::unordered_multimap<Key,void*,Hash,Pred,Allocator>, |
| 142 | CloneAllocator,false> |
| 143 | base_type; |
| 144 | |
| 145 | typedef ptr_unordered_multimap<Key,T,Hash,Pred,CloneAllocator,Allocator> this_type; |
| 146 | |
| 147 | public: |
| 148 | typedef typename base_type::size_type size_type; |
| 149 | |
| 150 | private: |
| 151 | using base_type::lower_bound; |
| 152 | using base_type::upper_bound; |
| 153 | using base_type::rbegin; |
| 154 | using base_type::rend; |
| 155 | using base_type::crbegin; |
| 156 | using base_type::crend; |
| 157 | using base_type::key_comp; |
| 158 | using base_type::value_comp; |
| 159 | using base_type::front; |
| 160 | using base_type::back; |
| 161 | |
| 162 | public: |
| 163 | using base_type::begin; |
| 164 | using base_type::end; |
| 165 | using base_type::cbegin; |
| 166 | using base_type::cend; |
| 167 | using base_type::bucket_count; |
| 168 | using base_type::max_bucket_count; |
| 169 | using base_type::bucket_size; |
| 170 | using base_type::bucket; |
| 171 | using base_type::load_factor; |
| 172 | using base_type::max_load_factor; |
| 173 | using base_type::rehash; |
| 174 | using base_type::key_eq; |
| 175 | using base_type::hash_function; |
| 176 | |
| 177 | public: |
| 178 | ptr_unordered_multimap() |
| 179 | { } |
| 180 | |
| 181 | explicit ptr_unordered_multimap( size_type n ) |
| 182 | : base_type( n, ptr_container_detail::unordered_associative_container_tag() ) |
| 183 | { } |
| 184 | |
| 185 | ptr_unordered_multimap( size_type n, |
| 186 | const Hash& comp, |
| 187 | const Pred& pred = Pred(), |
| 188 | const Allocator& a = Allocator() ) |
| 189 | : base_type( n, comp, pred, a ) |
| 190 | { } |
| 191 | |
| 192 | template< typename InputIterator > |
| 193 | ptr_unordered_multimap( InputIterator first, InputIterator last ) |
| 194 | : base_type( first, last ) |
| 195 | { } |
| 196 | |
| 197 | template< typename InputIterator > |
| 198 | ptr_unordered_multimap( InputIterator first, InputIterator last, |
| 199 | const Hash& comp, |
| 200 | const Pred& pred = Pred(), |
| 201 | const Allocator& a = Allocator() ) |
| 202 | : base_type( first, last, comp, pred, a ) |
| 203 | { } |
| 204 | |
| 205 | BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_multimap, |
| 206 | base_type, |
| 207 | this_type ) |
| 208 | |
| 209 | template< class U > |
| 210 | ptr_unordered_multimap( const ptr_unordered_multimap<Key,U>& r ) : base_type( r ) |
| 211 | { } |
| 212 | |
| 213 | ptr_unordered_multimap& operator=( ptr_unordered_multimap r ) |
| 214 | { |
| 215 | this->swap( r ); |
| 216 | return *this; |
| 217 | } |
| 218 | }; |
| 219 | |
| 220 | ////////////////////////////////////////////////////////////////////////////// |
| 221 | // clonability |
| 222 | |
| 223 | template< class K, class T, class H, class P, class CA, class A > |
| 224 | inline ptr_unordered_map<K,T,H,P,CA,A>* |
| 225 | new_clone( const ptr_unordered_map<K,T,H,P,CA,A>& r ) |
| 226 | { |
| 227 | return r.clone().release(); |
| 228 | } |
| 229 | |
| 230 | template< class K, class T, class H, class P, class CA, class A > |
| 231 | inline ptr_unordered_multimap<K,T,H,P,CA,A>* |
| 232 | new_clone( const ptr_unordered_multimap<K,T,H,P,CA,A>& r ) |
| 233 | { |
| 234 | return r.clone().release(); |
| 235 | } |
| 236 | |
| 237 | ///////////////////////////////////////////////////////////////////////// |
| 238 | // swap |
| 239 | |
| 240 | template< class K, class T, class H, class P, class CA, class A > |
| 241 | inline void swap( ptr_unordered_map<K,T,H,P,CA,A>& l, |
| 242 | ptr_unordered_map<K,T,H,P,CA,A>& r ) |
| 243 | { |
| 244 | l.swap(r); |
| 245 | } |
| 246 | |
| 247 | template< class K, class T, class H, class P, class CA, class A > |
| 248 | inline void swap( ptr_unordered_multimap<K,T,H,P,CA,A>& l, |
| 249 | ptr_unordered_multimap<K,T,H,P,CA,A>& r ) |
| 250 | { |
| 251 | l.swap(r); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | } |
| 256 | |
| 257 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) |
| 258 | #pragma GCC diagnostic pop |
| 259 | #endif |
| 260 | |
| 261 | #endif |
| 262 | |