| 1 |
/* Copyright (C) 2015 Povilas Kanapickas <[email protected]> |
| 2 |
|
| 3 |
This file is part of cppreference-doc |
| 4 |
|
| 5 |
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 |
| 6 |
Unported License. To view a copy of this license, visit |
| 7 |
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative |
| 8 |
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. |
| 9 |
|
| 10 |
Permission is granted to copy, distribute and/or modify this document |
| 11 |
under the terms of the GNU Free Documentation License, Version 1.3 or |
| 12 |
any later version published by the Free Software Foundation; with no |
| 13 |
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifndef CPPREFERENCE_UNORDERED_MAP_H |
| 17 |
#define CPPREFERENCE_UNORDERED_MAP_H |
| 18 |
|
| 19 |
#if CPPREFERENCE_STDVER>= 2011 |
| 20 |
#include <initializer_list> |
| 21 |
|
| 22 |
namespace std { |
| 23 |
|
| 24 |
template < |
| 25 |
class Key, |
| 26 |
class T, |
| 27 |
class Hash = std::hash<Key>, |
| 28 |
class KeyEqual = std::equal_to<Key>, |
| 29 |
class Allocator = std::allocator<std::pair<const Key, T>> |
| 30 |
> class unordered_map { |
| 31 |
public: |
| 32 |
typedef Key key_type; |
| 33 |
typedef T mapped_type; |
| 34 |
typedef pair<const Key, T> value_type; |
| 35 |
typedef size_t size_type; // actual type unspecified |
| 36 |
typedef ptrdiff_t difference_type; // actual type not specified |
| 37 |
typedef Allocator allocator_type; |
| 38 |
typedef Hash hasher; |
| 39 |
typedef KeyEqual key_equal; |
| 40 |
typedef value_type& reference; |
| 41 |
typedef const value_type& const_reference; |
| 42 |
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS |
| 43 |
typedef value_type* pointer; |
| 44 |
typedef const value_type* const_pointer; |
| 45 |
#else |
| 46 |
typedef typename std::allocator_traits<Allocator>::pointer pointer; |
| 47 |
typedef typename std::allocator_traits<Allocator>::const_pointer const_pointer; |
| 48 |
#endif |
| 49 |
typedef T* iterator; // actual type is unspecified |
| 50 |
typedef const T* const_iterator; // actual type is unspecified |
| 51 |
typedef T* local_iterator; // actual type is unspecified |
| 52 |
typedef const T* const_local_iterator; // actual type is unspecified |
| 53 |
|
| 54 |
// constructor |
| 55 |
// constructor |
| 56 |
#if CPPREFERENCE_STDVER <2014 |
| 57 |
explicit unordered_map(size_type bucket_count = 0 /*implementation-defined*/, |
| 58 |
const Hash& hash = Hash(), |
| 59 |
const KeyEqual& equal = KeyEqual(), |
| 60 |
const Allocator& alloc = Allocator()); |
| 61 |
#else |
| 62 |
unordered_map(); |
| 63 |
|
| 64 |
explicit unordered_map(size_type bucket_count, |
| 65 |
const Hash& hash = Hash(), |
| 66 |
const KeyEqual& equal = KeyEqual(), |
| 67 |
const Allocator& alloc = Allocator()); |
| 68 |
|
| 69 |
unordered_map(size_type bucket_count, |
| 70 |
const Allocator& alloc); |
| 71 |
|
| 72 |
unordered_map(size_type bucket_count, |
| 73 |
const Hash& hash, |
| 74 |
const Allocator& alloc); |
| 75 |
#endif |
| 76 |
|
| 77 |
explicit unordered_map(const Allocator& alloc); |
| 78 |
|
| 79 |
template<class InputIt> |
| 80 |
unordered_map(InputIt first, InputIt last, |
| 81 |
size_type bucket_count = 0 /*implementation-defined*/, |
| 82 |
const Hash& hash = Hash(), |
| 83 |
const KeyEqual& equal = KeyEqual(), |
| 84 |
const Allocator& alloc = Allocator()); |
| 85 |
|
| 86 |
#if CPPREFERENCE_STDVER>= 2014 |
| 87 |
template<class InputIt> |
| 88 |
unordered_map(InputIt first, InputIt last, |
| 89 |
size_type bucket_count, |
| 90 |
const Allocator& alloc); |
| 91 |
|
| 92 |
template<class InputIt> |
| 93 |
unordered_map(InputIt first, InputIt last, |
| 94 |
size_type bucket_count, |
| 95 |
const Hash& hash, |
| 96 |
const Allocator& alloc); |
| 97 |
#endif |
| 98 |
|
| 99 |
unordered_map(const unordered_map& other); |
| 100 |
unordered_map(const unordered_map& other, const Allocator& alloc); |
| 101 |
unordered_map(unordered_map&& other); |
| 102 |
unordered_map(unordered_map&& other, const Allocator& alloc); |
| 103 |
|
| 104 |
unordered_map(std::initializer_list<value_type> init, |
| 105 |
size_type bucket_count = /*implementation-defined*/, |
| 106 |
const Hash& hash = Hash(), |
| 107 |
const KeyEqual& equal = KeyEqual(), |
| 108 |
const Allocator& alloc = Allocator()); |
| 109 |
|
| 110 |
#if CPPREFERENCE_STDVER>= 2014 |
| 111 |
unordered_map(std::initializer_list<value_type> init, |
| 112 |
size_type bucket_count, |
| 113 |
const Allocator& alloc); |
| 114 |
|
| 115 |
unordered_map(std::initializer_list<value_type> init, |
| 116 |
size_type bucket_count, |
| 117 |
const Hash& hash, |
| 118 |
const Allocator& alloc); |
| 119 |
#endif |
| 120 |
|
| 121 |
#if CPPREFERENCE_STDVER>= 2014 |
| 122 |
unordered_map(std::initializer_list<value_type> init, const Allocator& alloc); |
| 123 |
#endif |
| 124 |
|
| 125 |
~unordered_map(); |
| 126 |
|
| 127 |
unordered_map& operator=(const unordered_map& other); |
| 128 |
unordered_map& operator=(unordered_map&& other); |
| 129 |
unordered_map& operator=(initializer_list<value_type> ilist); |
| 130 |
|
| 131 |
allocator_type get_allocator() const; |
| 132 |
|
| 133 |
// element access |
| 134 |
T& operator[](const Key& key); |
| 135 |
T& operator[](Key&& key); |
| 136 |
T& at(const Key& key); |
| 137 |
const T& at(const Key& key) const; |
| 138 |
|
| 139 |
// iterators |
| 140 |
iterator begin(); |
| 141 |
const_iterator begin() const; |
| 142 |
iterator end(); |
| 143 |
const_iterator end() const; |
| 144 |
|
| 145 |
reverse_iterator rbegin(); |
| 146 |
const_reverse_iterator rbegin() const; |
| 147 |
reverse_iterator rend(); |
| 148 |
const_reverse_iterator rend() const; |
| 149 |
|
| 150 |
const_iterator cbegin() const; |
| 151 |
const_iterator cend() const; |
| 152 |
const_reverse_iterator crbegin() const; |
| 153 |
const_reverse_iterator crend() const; |
| 154 |
|
| 155 |
// capacity |
| 156 |
bool empty() const; |
| 157 |
size_type size() const; |
| 158 |
size_type max_size() const; |
| 159 |
|
| 160 |
// modifiers |
| 161 |
void clear(); |
| 162 |
|
| 163 |
std::pair<iterator, bool> insert(const value_type& value); |
| 164 |
template<class P> |
| 165 |
std::pair<iterator, bool> insert(P&& value); |
| 166 |
std::pair<iterator, bool> insert(value_type&& value); |
| 167 |
iterator insert(const_iterator hint, const value_type& value); |
| 168 |
|
| 169 |
template<class P> |
| 170 |
iterator insert(const_iterator hint, P&& value); |
| 171 |
|
| 172 |
template<class InputIt> |
| 173 |
void insert(InputIt first, InputIt last); |
| 174 |
|
| 175 |
void insert(std::initializer_list<value_type> ilist); |
| 176 |
|
| 177 |
template<class... Args> |
| 178 |
std::pair<iterator, bool> emplace(Args&& ... args); |
| 179 |
|
| 180 |
template <class... Args> |
| 181 |
iterator emplace_hint(const_iterator hint, Args&& ... args); |
| 182 |
|
| 183 |
iterator erase(const_iterator pos); |
| 184 |
iterator erase(const_iterator first, const_iterator last); |
| 185 |
size_type erase(const key_type& key); |
| 186 |
|
| 187 |
void swap(unordered_map& other); |
| 188 |
|
| 189 |
// lookup |
| 190 |
size_type count(const Key& key) const; |
| 191 |
|
| 192 |
iterator find(const Key& key); |
| 193 |
const_iterator find(const Key& key) const; |
| 194 |
|
| 195 |
std::pair<iterator, iterator> equal_range(const Key& key); |
| 196 |
std::pair<const_iterator, const_iterator> equal_range(const Key& key) const; |
| 197 |
|
| 198 |
// bucket interface |
| 199 |
local_iterator begin(size_type n); |
| 200 |
const_local_iterator begin(size_type n) const; |
| 201 |
const_local_iterator cbegin(size_type n) const; |
| 202 |
|
| 203 |
local_iterator end(size_type n); |
| 204 |
const_local_iterator end(size_type n) const; |
| 205 |
const_local_iterator cend(size_type n) const; |
| 206 |
|
| 207 |
size_type bucket_count() const; |
| 208 |
size_type max_bucket_count() const; |
| 209 |
size_type bucket_size(size_type n) const; |
| 210 |
size_type bucket(const Key& key) const; |
| 211 |
float load_factor() const; |
| 212 |
float max_load_factor() const; |
| 213 |
void max_load_factor(float ml); |
| 214 |
void rehash(size_type count); |
| 215 |
void reserve(size_type count); |
| 216 |
|
| 217 |
// observers |
| 218 |
hasher hash_function() const; |
| 219 |
key_equal key_eq() const; |
| 220 |
}; |
| 221 |
|
| 222 |
template<class Key, class T, class Hash, class KeyEqual, class Allocator> |
| 223 |
bool operator==(const unordered_map<Key, T, Hash, KeyEqual, Allocator>& lhs, |
| 224 |
const unordered_map<Key, T, Hash, KeyEqual, Allocator>& rhs); |
| 225 |
|
| 226 |
template<class Key, class T, class Hash, class KeyEqual, class Allocator> |
| 227 |
bool operator!=(const unordered_map<Key, T, Hash, KeyEqual, Allocator>& lhs, |
| 228 |
const unordered_map<Key, T, Hash, KeyEqual, Allocator>& rhs); |
| 229 |
|
| 230 |
template<class Key, class T, class Hash, class KeyEqual, class Alloc> |
| 231 |
void swap(unordered_map<Key, T, Hash, KeyEqual, Alloc>& lhs, |
| 232 |
unordered_map<Key, T, Hash, KeyEqual, Alloc>& rhs); |
| 233 |
|
| 234 |
template < |
| 235 |
class Key, |
| 236 |
class T, |
| 237 |
class Hash = std::hash<Key>, |
| 238 |
class KeyEqual = std::equal_to<Key>, |
| 239 |
class Allocator = std::allocator<std::pair<const Key, T>> |
| 240 |
> class unordered_multimap { |
| 241 |
public: |
| 242 |
typedef Key key_type; |
| 243 |
typedef T mapped_type; |
| 244 |
typedef pair<const Key, T> value_type; |
| 245 |
typedef size_t size_type; // actual type unspecified |
| 246 |
typedef ptrdiff_t difference_type; // actual type not specified |
| 247 |
typedef Allocator allocator_type; |
| 248 |
typedef Hash hasher; |
| 249 |
typedef KeyEqual key_equal; |
| 250 |
typedef value_type& reference; |
| 251 |
typedef const value_type& const_reference; |
| 252 |
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS |
| 253 |
typedef value_type* pointer; |
| 254 |
typedef const value_type* const_pointer; |
| 255 |
#else |
| 256 |
typedef typename std::allocator_traits<Allocator>::pointer pointer; |
| 257 |
typedef typename std::allocator_traits<Allocator>::const_pointer const_pointer; |
| 258 |
#endif |
| 259 |
typedef T* iterator; // actual type is unspecified |
| 260 |
typedef const T* const_iterator; // actual type is unspecified |
| 261 |
typedef T* local_iterator; // actual type is unspecified |
| 262 |
typedef const T* const_local_iterator; // actual type is unspecified |
| 263 |
|
| 264 |
// constructor |
| 265 |
// constructor |
| 266 |
#if CPPREFERENCE_STDVER <2014 |
| 267 |
explicit unordered_multimap(size_type bucket_count = 0 /*implementation-defined*/, |
| 268 |
const Hash& hash = Hash(), |
| 269 |
const KeyEqual& equal = KeyEqual(), |
| 270 |
const Allocator& alloc = Allocator()); |
| 271 |
#else |
| 272 |
unordered_multimap(); |
| 273 |
|
| 274 |
explicit unordered_multimap(size_type bucket_count, |
| 275 |
const Hash& hash = Hash(), |
| 276 |
const KeyEqual& equal = KeyEqual(), |
| 277 |
const Allocator& alloc = Allocator()); |
| 278 |
|
| 279 |
unordered_multimap(size_type bucket_count, |
| 280 |
const Allocator& alloc); |
| 281 |
|
| 282 |
unordered_multimap(size_type bucket_count, |
| 283 |
const Hash& hash, |
| 284 |
const Allocator& alloc); |
| 285 |
#endif |
| 286 |
|
| 287 |
explicit unordered_multimap(const Allocator& alloc); |
| 288 |
|
| 289 |
template<class InputIt> |
| 290 |
unordered_multimap(InputIt first, InputIt last, |
| 291 |
size_type bucket_count = 0 /*implementation-defined*/, |
| 292 |
const Hash& hash = Hash(), |
| 293 |
const KeyEqual& equal = KeyEqual(), |
| 294 |
const Allocator& alloc = Allocator()); |
| 295 |
|
| 296 |
#if CPPREFERENCE_STDVER>= 2014 |
| 297 |
template<class InputIt> |
| 298 |
unordered_multimap(InputIt first, InputIt last, |
| 299 |
size_type bucket_count, |
| 300 |
const Allocator& alloc); |
| 301 |
|
| 302 |
template<class InputIt> |
| 303 |
unordered_multimap(InputIt first, InputIt last, |
| 304 |
size_type bucket_count, |
| 305 |
const Hash& hash, |
| 306 |
const Allocator& alloc); |
| 307 |
#endif |
| 308 |
|
| 309 |
unordered_multimap(const unordered_multimap& other); |
| 310 |
unordered_multimap(const unordered_multimap& other, const Allocator& alloc); |
| 311 |
unordered_multimap(unordered_multimap&& other); |
| 312 |
unordered_multimap(unordered_multimap&& other, const Allocator& alloc); |
| 313 |
|
| 314 |
unordered_multimap(std::initializer_list<value_type> init, |
| 315 |
size_type bucket_count = /*implementation-defined*/, |
| 316 |
const Hash& hash = Hash(), |
| 317 |
const KeyEqual& equal = KeyEqual(), |
| 318 |
const Allocator& alloc = Allocator()); |
| 319 |
|
| 320 |
#if CPPREFERENCE_STDVER>= 2014 |
| 321 |
unordered_multimap(std::initializer_list<value_type> init, |
| 322 |
size_type bucket_count, |
| 323 |
const Allocator& alloc); |
| 324 |
|
| 325 |
unordered_multimap(std::initializer_list<value_type> init, |
| 326 |
size_type bucket_count, |
| 327 |
const Hash& hash, |
| 328 |
const Allocator& alloc); |
| 329 |
#endif |
| 330 |
|
| 331 |
#if CPPREFERENCE_STDVER>= 2014 |
| 332 |
unordered_multimap(std::initializer_list<value_type> init, const Allocator& alloc); |
| 333 |
#endif |
| 334 |
|
| 335 |
~unordered_multimap(); |
| 336 |
|
| 337 |
unordered_multimap& operator=(const unordered_multimap& other); |
| 338 |
unordered_multimap& operator=(unordered_multimap&& other); |
| 339 |
unordered_multimap& operator=(initializer_list<value_type> ilist); |
| 340 |
|
| 341 |
allocator_type get_allocator() const; |
| 342 |
|
| 343 |
// iterators |
| 344 |
iterator begin(); |
| 345 |
const_iterator begin() const; |
| 346 |
iterator end(); |
| 347 |
const_iterator end() const; |
| 348 |
|
| 349 |
reverse_iterator rbegin(); |
| 350 |
const_reverse_iterator rbegin() const; |
| 351 |
reverse_iterator rend(); |
| 352 |
const_reverse_iterator rend() const; |
| 353 |
|
| 354 |
const_iterator cbegin() const; |
| 355 |
const_iterator cend() const; |
| 356 |
const_reverse_iterator crbegin() const; |
| 357 |
const_reverse_iterator crend() const; |
| 358 |
|
| 359 |
// capacity |
| 360 |
bool empty() const; |
| 361 |
size_type size() const; |
| 362 |
size_type max_size() const; |
| 363 |
|
| 364 |
// modifiers |
| 365 |
void clear(); |
| 366 |
|
| 367 |
std::pair<iterator, bool> insert(const value_type& value); |
| 368 |
template<class P> |
| 369 |
std::pair<iterator, bool> insert(P&& value); |
| 370 |
std::pair<iterator, bool> insert(value_type&& value); |
| 371 |
iterator insert(const_iterator hint, const value_type& value); |
| 372 |
|
| 373 |
template<class P> |
| 374 |
iterator insert(const_iterator hint, P&& value); |
| 375 |
|
| 376 |
template<class InputIt> |
| 377 |
void insert(InputIt first, InputIt last); |
| 378 |
|
| 379 |
void insert(std::initializer_list<value_type> ilist); |
| 380 |
|
| 381 |
template<class... Args> |
| 382 |
std::pair<iterator, bool> emplace(Args&& ... args); |
| 383 |
|
| 384 |
template <class... Args> |
| 385 |
iterator emplace_hint(const_iterator hint, Args&& ... args); |
| 386 |
|
| 387 |
iterator erase(const_iterator pos); |
| 388 |
iterator erase(const_iterator first, const_iterator last); |
| 389 |
size_type erase(const key_type& key); |
| 390 |
|
| 391 |
void swap(unordered_multimap& other); |
| 392 |
|
| 393 |
// lookup |
| 394 |
size_type count(const Key& key) const; |
| 395 |
|
| 396 |
iterator find(const Key& key); |
| 397 |
const_iterator find(const Key& key) const; |
| 398 |
|
| 399 |
std::pair<iterator, iterator> equal_range(const Key& key); |
| 400 |
std::pair<const_iterator, const_iterator> equal_range(const Key& key) const; |
| 401 |
|
| 402 |
// bucket interface |
| 403 |
local_iterator begin(size_type n); |
| 404 |
const_local_iterator begin(size_type n) const; |
| 405 |
const_local_iterator cbegin(size_type n) const; |
| 406 |
|
| 407 |
local_iterator end(size_type n); |
| 408 |
const_local_iterator end(size_type n) const; |
| 409 |
const_local_iterator cend(size_type n) const; |
| 410 |
|
| 411 |
size_type bucket_count() const; |
| 412 |
size_type max_bucket_count() const; |
| 413 |
size_type bucket_size(size_type n) const; |
| 414 |
size_type bucket(const Key& key) const; |
| 415 |
float load_factor() const; |
| 416 |
float max_load_factor() const; |
| 417 |
void max_load_factor(float ml); |
| 418 |
void rehash(size_type count); |
| 419 |
void reserve(size_type count); |
| 420 |
|
| 421 |
// observers |
| 422 |
hasher hash_function() const; |
| 423 |
key_equal key_eq() const; |
| 424 |
}; |
| 425 |
|
| 426 |
template<class Key, class T, class Hash, class KeyEqual, class Allocator> |
| 427 |
bool operator==(const unordered_multimap<Key, T, Hash, KeyEqual, Allocator>& lhs, |
| 428 |
const unordered_multimap<Key, T, Hash, KeyEqual, Allocator>& rhs); |
| 429 |
|
| 430 |
template<class Key, class T, class Hash, class KeyEqual, class Allocator> |
| 431 |
bool operator!=(const unordered_multimap<Key, T, Hash, KeyEqual, Allocator>& lhs, |
| 432 |
const unordered_multimap<Key, T, Hash, KeyEqual, Allocator>& rhs); |
| 433 |
|
| 434 |
template<class Key, class T, class Hash, class KeyEqual, class Alloc> |
| 435 |
void swap(unordered_multimap<Key, T, Hash, KeyEqual, Alloc>& lhs, |
| 436 |
unordered_multimap<Key, T, Hash, KeyEqual, Alloc>& rhs); |
| 437 |
|
| 438 |
|
| 439 |
} // namespace std |
| 440 |
|
| 441 |
#endif // CPPREFERENCE_STDVER>= 2011 |
| 442 |
|
| 443 |
#endif // CPPREFERENCE_UNORDERED_MAP_H |