| 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_SET_H |
| 17 |
#define CPPREFERENCE_UNORDERED_SET_H |
| 18 |
|
| 19 |
#if CPPREFERENCE_STDVER>= 2011 |
| 20 |
#include <initializer_list> |
| 21 |
|
| 22 |
namespace std { |
| 23 |
|
| 24 |
template < |
| 25 |
class Key, |
| 26 |
class Hash = std::hash<Key>, |
| 27 |
class KeyEqual = std::equal_to<Key>, |
| 28 |
class Allocator = std::allocator<Key> |
| 29 |
> class unordered_set { |
| 30 |
public: |
| 31 |
typedef Key key_type; |
| 32 |
typedef Key value_type; |
| 33 |
typedef size_t size_type; // actual type unspecified |
| 34 |
typedef ptrdiff_t difference_type; // actual type not specified |
| 35 |
typedef Hash hasher; |
| 36 |
typedef KeyEqual key_equal; |
| 37 |
typedef Allocator allocator_type; |
| 38 |
typedef value_type& reference; |
| 39 |
typedef const value_type& const_reference; |
| 40 |
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS |
| 41 |
typedef value_type* pointer; |
| 42 |
typedef const value_type* const_pointer; |
| 43 |
#else |
| 44 |
typedef typename std::allocator_traits<Allocator>::pointer pointer; |
| 45 |
typedef typename std::allocator_traits<Allocator>::const_pointer const_pointer; |
| 46 |
#endif |
| 47 |
typedef T* iterator; // actual type is unspecified |
| 48 |
typedef const T* const_iterator; // actual type is unspecified |
| 49 |
typedef T* local_iterator; // actual type is unspecified |
| 50 |
typedef const T* const_local_iterator; // actual type is unspecified |
| 51 |
|
| 52 |
// constructor |
| 53 |
#if CPPREFERENCE_STDVER <2014 |
| 54 |
explicit unordered_set(size_type bucket_count = 0 /*implementation-defined*/, |
| 55 |
const Hash& hash = Hash(), |
| 56 |
const KeyEqual& equal = KeyEqual(), |
| 57 |
const Allocator& alloc = Allocator()); |
| 58 |
#else |
| 59 |
unordered_set(); |
| 60 |
|
| 61 |
explicit unordered_set(size_type bucket_count, |
| 62 |
const Hash& hash = Hash(), |
| 63 |
const KeyEqual& equal = KeyEqual(), |
| 64 |
const Allocator& alloc = Allocator()); |
| 65 |
|
| 66 |
unordered_set(size_type bucket_count, |
| 67 |
const Allocator& alloc); |
| 68 |
|
| 69 |
unordered_set(size_type bucket_count, |
| 70 |
const Hash& hash, |
| 71 |
const Allocator& alloc); |
| 72 |
#endif |
| 73 |
|
| 74 |
explicit unordered_set(const Allocator& alloc); |
| 75 |
|
| 76 |
template<class InputIt> |
| 77 |
unordered_set(InputIt first, InputIt last, |
| 78 |
size_type bucket_count = 0 /*implementation-defined*/, |
| 79 |
const Hash& hash = Hash(), |
| 80 |
const KeyEqual& equal = KeyEqual(), |
| 81 |
const Allocator& alloc = Allocator()); |
| 82 |
|
| 83 |
#if CPPREFERENCE_STDVER>= 2014 |
| 84 |
template<class InputIt> |
| 85 |
unordered_set(InputIt first, InputIt last, |
| 86 |
size_type bucket_count, |
| 87 |
const Allocator& alloc); |
| 88 |
|
| 89 |
template<class InputIt> |
| 90 |
unordered_set(InputIt first, InputIt last, |
| 91 |
size_type bucket_count, |
| 92 |
const Hash& hash, |
| 93 |
const Allocator& alloc); |
| 94 |
#endif |
| 95 |
|
| 96 |
unordered_set(const unordered_set& other); |
| 97 |
unordered_set(const unordered_set& other, const Allocator& alloc); |
| 98 |
unordered_set(unordered_set&& other); |
| 99 |
unordered_set(unordered_set&& other, const Allocator& alloc); |
| 100 |
|
| 101 |
unordered_set(std::initializer_list<value_type> init, |
| 102 |
size_type bucket_count = /*implementation-defined*/, |
| 103 |
const Hash& hash = Hash(), |
| 104 |
const KeyEqual& equal = KeyEqual(), |
| 105 |
const Allocator& alloc = Allocator()); |
| 106 |
|
| 107 |
#if CPPREFERENCE_STDVER>= 2014 |
| 108 |
unordered_set(std::initializer_list<value_type> init, |
| 109 |
size_type bucket_count, |
| 110 |
const Allocator& alloc); |
| 111 |
|
| 112 |
unordered_set(std::initializer_list<value_type> init, |
| 113 |
size_type bucket_count, |
| 114 |
const Hash& hash, |
| 115 |
const Allocator& alloc); |
| 116 |
#endif |
| 117 |
|
| 118 |
#if CPPREFERENCE_STDVER>= 2014 |
| 119 |
unordered_set(std::initializer_list<value_type> init, const Allocator& alloc); |
| 120 |
#endif |
| 121 |
|
| 122 |
~unordered_set(); |
| 123 |
|
| 124 |
unordered_set& operator=(const unordered_set& other); |
| 125 |
unordered_set& operator=(unordered_set&& other); |
| 126 |
unordered_set& operator=(initializer_list<value_type> ilist); |
| 127 |
|
| 128 |
allocator_type get_allocator() const; |
| 129 |
|
| 130 |
// iterators |
| 131 |
iterator begin(); |
| 132 |
const_iterator begin() const; |
| 133 |
iterator end(); |
| 134 |
const_iterator end() const; |
| 135 |
|
| 136 |
const_iterator cbegin() const; |
| 137 |
const_iterator cend() const; |
| 138 |
|
| 139 |
// capacity |
| 140 |
bool empty() const; |
| 141 |
size_type size() const; |
| 142 |
size_type max_size() const; |
| 143 |
|
| 144 |
// modifiers |
| 145 |
void clear(); |
| 146 |
|
| 147 |
std::pair<iterator, bool> insert(const value_type& value); |
| 148 |
std::pair<iterator, bool> insert(value_type&& value); |
| 149 |
iterator insert(const_iterator hint, const value_type& value); |
| 150 |
iterator insert(const_iterator hint, value_type&& value); |
| 151 |
|
| 152 |
template<class InputIt> |
| 153 |
void insert(InputIt first, InputIt last); |
| 154 |
void insert(std::initializer_list<value_type> ilist); |
| 155 |
|
| 156 |
template<class... Args> |
| 157 |
std::pair<iterator, bool> emplace(Args&& ... args); |
| 158 |
|
| 159 |
template <class... Args> |
| 160 |
iterator emplace_hint(const_iterator hint, Args&& ... args); |
| 161 |
|
| 162 |
iterator erase(const_iterator pos); |
| 163 |
iterator erase(const_iterator first, const_iterator last); |
| 164 |
size_type erase(const key_type& key); |
| 165 |
|
| 166 |
void swap(unordered_set& other); |
| 167 |
|
| 168 |
// lookup |
| 169 |
size_type count(const Key& key) const; |
| 170 |
|
| 171 |
iterator find(const Key& key); |
| 172 |
const_iterator find(const Key& key) const; |
| 173 |
|
| 174 |
std::pair<iterator, iterator> equal_range(const Key& key); |
| 175 |
std::pair<const_iterator, const_iterator> equal_range(const Key& key) const; |
| 176 |
|
| 177 |
// bucket interface |
| 178 |
local_iterator begin(size_type n); |
| 179 |
const_local_iterator begin(size_type n) const; |
| 180 |
const_local_iterator cbegin(size_type n) const; |
| 181 |
|
| 182 |
local_iterator end(size_type n); |
| 183 |
const_local_iterator end(size_type n) const; |
| 184 |
const_local_iterator cend(size_type n) const; |
| 185 |
|
| 186 |
size_type bucket_count() const; |
| 187 |
size_type max_bucket_count() const; |
| 188 |
size_type bucket_size(size_type n) const; |
| 189 |
size_type bucket(const Key& key) const; |
| 190 |
float load_factor() const; |
| 191 |
float max_load_factor() const; |
| 192 |
void max_load_factor(float ml); |
| 193 |
void rehash(size_type count); |
| 194 |
void reserve(size_type count); |
| 195 |
|
| 196 |
// observers |
| 197 |
hasher hash_function() const; |
| 198 |
key_equal key_eq() const; |
| 199 |
}; |
| 200 |
|
| 201 |
template<class Key, class Hash, class KeyEqual, class Allocator> |
| 202 |
bool operator==(const unordered_set<Key, Hash, KeyEqual, Allocator>& lhs, |
| 203 |
const unordered_set<Key, Hash, KeyEqual, Allocator>& rhs); |
| 204 |
|
| 205 |
template<class Key, class Hash, class KeyEqual, class Allocator> |
| 206 |
bool operator!=(const unordered_set<Key, Hash, KeyEqual, Allocator>& lhs, |
| 207 |
const unordered_set<Key, Hash, KeyEqual, Allocator>& rhs); |
| 208 |
|
| 209 |
template<class Key, class Hash, class KeyEqual, class Alloc> |
| 210 |
void swap(unordered_set<Key, Hash, KeyEqual, Alloc>& lhs, |
| 211 |
unordered_set<Key, Hash, KeyEqual, Alloc>& rhs); |
| 212 |
|
| 213 |
template < |
| 214 |
class Key, |
| 215 |
class Hash = std::hash<Key>, |
| 216 |
class KeyEqual = std::equal_to<Key>, |
| 217 |
class Allocator = std::allocator<Key> |
| 218 |
> class unordered_multiset { |
| 219 |
public: |
| 220 |
typedef Key key_type; |
| 221 |
typedef Key value_type; |
| 222 |
typedef size_t size_type; // actual type unspecified |
| 223 |
typedef ptrdiff_t difference_type; // actual type not specified |
| 224 |
typedef Hash hasher; |
| 225 |
typedef KeyEqual key_equal; |
| 226 |
typedef Allocator allocator_type; |
| 227 |
typedef value_type& reference; |
| 228 |
typedef const value_type& const_reference; |
| 229 |
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS |
| 230 |
typedef value_type* pointer; |
| 231 |
typedef const value_type* const_pointer; |
| 232 |
#else |
| 233 |
typedef typename std::allocator_traits<Allocator>::pointer pointer; |
| 234 |
typedef typename std::allocator_traits<Allocator>::const_pointer const_pointer; |
| 235 |
#endif |
| 236 |
typedef T* iterator; // actual type is unspecified |
| 237 |
typedef const T* const_iterator; // actual type is unspecified |
| 238 |
typedef T* local_iterator; // actual type is unspecified |
| 239 |
typedef const T* const_local_iterator; // actual type is unspecified |
| 240 |
|
| 241 |
// constructor |
| 242 |
|
| 243 |
|
| 244 |
#if CPPREFERENCE_STDVER <2014 |
| 245 |
explicit unordered_multiset(size_type bucket_count = 0 /*implementation-defined*/, |
| 246 |
const Hash& hash = Hash(), |
| 247 |
const KeyEqual& equal = KeyEqual(), |
| 248 |
const Allocator& alloc = Allocator()); |
| 249 |
#else |
| 250 |
unordered_multiset(); |
| 251 |
|
| 252 |
explicit unordered_multiset(size_type bucket_count, |
| 253 |
const Hash& hash = Hash(), |
| 254 |
const KeyEqual& equal = KeyEqual(), |
| 255 |
const Allocator& alloc = Allocator()); |
| 256 |
|
| 257 |
unordered_multiset(size_type bucket_count, |
| 258 |
const Allocator& alloc); |
| 259 |
|
| 260 |
unordered_multiset(size_type bucket_count, |
| 261 |
const Hash& hash, |
| 262 |
const Allocator& alloc); |
| 263 |
#endif |
| 264 |
|
| 265 |
explicit unordered_multiset(const Allocator& alloc); |
| 266 |
|
| 267 |
template<class InputIt> |
| 268 |
unordered_multiset(InputIt first, InputIt last, |
| 269 |
size_type bucket_count = 0 /*implementation-defined*/, |
| 270 |
const Hash& hash = Hash(), |
| 271 |
const KeyEqual& equal = KeyEqual(), |
| 272 |
const Allocator& alloc = Allocator()); |
| 273 |
|
| 274 |
#if CPPREFERENCE_STDVER>= 2014 |
| 275 |
template<class InputIt> |
| 276 |
unordered_multiset(InputIt first, InputIt last, |
| 277 |
size_type bucket_count, |
| 278 |
const Allocator& alloc); |
| 279 |
|
| 280 |
template<class InputIt> |
| 281 |
unordered_multiset(InputIt first, InputIt last, |
| 282 |
size_type bucket_count, |
| 283 |
const Hash& hash, |
| 284 |
const Allocator& alloc); |
| 285 |
#endif |
| 286 |
|
| 287 |
unordered_multiset(const unordered_multiset& other); |
| 288 |
unordered_multiset(const unordered_multiset& other, const Allocator& alloc); |
| 289 |
unordered_multiset(unordered_multiset&& other); |
| 290 |
unordered_multiset(unordered_multiset&& other, const Allocator& alloc); |
| 291 |
|
| 292 |
unordered_multiset(std::initializer_list<value_type> init, |
| 293 |
size_type bucket_count = /*implementation-defined*/, |
| 294 |
const Hash& hash = Hash(), |
| 295 |
const KeyEqual& equal = KeyEqual(), |
| 296 |
const Allocator& alloc = Allocator()); |
| 297 |
|
| 298 |
#if CPPREFERENCE_STDVER>= 2014 |
| 299 |
unordered_multiset(std::initializer_list<value_type> init, |
| 300 |
size_type bucket_count, |
| 301 |
const Allocator& alloc); |
| 302 |
|
| 303 |
unordered_multiset(std::initializer_list<value_type> init, |
| 304 |
size_type bucket_count, |
| 305 |
const Hash& hash, |
| 306 |
const Allocator& alloc); |
| 307 |
#endif |
| 308 |
|
| 309 |
#if CPPREFERENCE_STDVER>= 2014 |
| 310 |
unordered_multiset(std::initializer_list<value_type> init, const Allocator& alloc); |
| 311 |
#endif |
| 312 |
|
| 313 |
~unordered_multiset(); |
| 314 |
|
| 315 |
unordered_multiset& operator=(const unordered_multiset& other); |
| 316 |
unordered_multiset& operator=(unordered_multiset&& other); |
| 317 |
unordered_multiset& operator=(initializer_list<value_type> ilist); |
| 318 |
|
| 319 |
allocator_type get_allocator() const; |
| 320 |
|
| 321 |
// iterators |
| 322 |
iterator begin(); |
| 323 |
const_iterator begin() const; |
| 324 |
iterator end(); |
| 325 |
const_iterator end() const; |
| 326 |
|
| 327 |
const_iterator cbegin() const; |
| 328 |
const_iterator cend() const; |
| 329 |
|
| 330 |
// capacity |
| 331 |
bool empty() const; |
| 332 |
size_type size() const; |
| 333 |
size_type max_size() const; |
| 334 |
|
| 335 |
// modifiers |
| 336 |
void clear(); |
| 337 |
|
| 338 |
std::pair<iterator, bool> insert(const value_type& value); |
| 339 |
std::pair<iterator, bool> insert(value_type&& value); |
| 340 |
iterator insert(const_iterator hint, const value_type& value); |
| 341 |
iterator insert(const_iterator hint, value_type&& value); |
| 342 |
|
| 343 |
template<class InputIt> |
| 344 |
void insert(InputIt first, InputIt last); |
| 345 |
void insert(std::initializer_list<value_type> ilist); |
| 346 |
|
| 347 |
template<class... Args> |
| 348 |
std::pair<iterator, bool> emplace(Args&& ... args); |
| 349 |
|
| 350 |
template <class... Args> |
| 351 |
iterator emplace_hint(const_iterator hint, Args&& ... args); |
| 352 |
|
| 353 |
iterator erase(const_iterator pos); |
| 354 |
iterator erase(const_iterator first, const_iterator last); |
| 355 |
size_type erase(const key_type& key); |
| 356 |
|
| 357 |
void swap(unordered_multiset& other); |
| 358 |
|
| 359 |
// lookup |
| 360 |
size_type count(const Key& key) const; |
| 361 |
|
| 362 |
iterator find(const Key& key); |
| 363 |
const_iterator find(const Key& key) const; |
| 364 |
|
| 365 |
std::pair<iterator, iterator> equal_range(const Key& key); |
| 366 |
std::pair<const_iterator, const_iterator> equal_range(const Key& key) const; |
| 367 |
|
| 368 |
// bucket interface |
| 369 |
local_iterator begin(size_type n); |
| 370 |
const_local_iterator begin(size_type n) const; |
| 371 |
const_local_iterator cbegin(size_type n) const; |
| 372 |
|
| 373 |
local_iterator end(size_type n); |
| 374 |
const_local_iterator end(size_type n) const; |
| 375 |
const_local_iterator cend(size_type n) const; |
| 376 |
|
| 377 |
size_type bucket_count() const; |
| 378 |
size_type max_bucket_count() const; |
| 379 |
size_type bucket_size(size_type n) const; |
| 380 |
size_type bucket(const Key& key) const; |
| 381 |
float load_factor() const; |
| 382 |
float max_load_factor() const; |
| 383 |
void max_load_factor(float ml); |
| 384 |
void rehash(size_type count); |
| 385 |
void reserve(size_type count); |
| 386 |
|
| 387 |
// observers |
| 388 |
hasher hash_function() const; |
| 389 |
key_equal key_eq() const; |
| 390 |
}; |
| 391 |
|
| 392 |
template<class Key, class Hash, class KeyEqual, class Allocator> |
| 393 |
bool operator==(const unordered_multiset<Key, Hash, KeyEqual, Allocator>& lhs, |
| 394 |
const unordered_multiset<Key, Hash, KeyEqual, Allocator>& rhs); |
| 395 |
|
| 396 |
template<class Key, class Hash, class KeyEqual, class Allocator> |
| 397 |
bool operator!=(const unordered_multiset<Key, Hash, KeyEqual, Allocator>& lhs, |
| 398 |
const unordered_multiset<Key, Hash, KeyEqual, Allocator>& rhs); |
| 399 |
|
| 400 |
template<class Key, class Hash, class KeyEqual, class Alloc> |
| 401 |
void swap(unordered_multiset<Key, Hash, KeyEqual, Alloc>& lhs, |
| 402 |
unordered_multiset<Key, Hash, KeyEqual, Alloc>& rhs); |
| 403 |
|
| 404 |
} // namespace std |
| 405 |
|
| 406 |
#endif // CPPREFERENCE_STDVER>= 2011 |