BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlc_flathashmap.h
Go to the documentation of this file.
1/// @file bdlc_flathashmap.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlc_flathashmap.h -*-C++-*-
8#ifndef INCLUDED_BDLC_FLATHASHMAP
9#define INCLUDED_BDLC_FLATHASHMAP
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlc_flathashmap bdlc_flathashmap
15/// @brief Provide an open-addressed unordered map container.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlc
19/// @{
20/// @addtogroup bdlc_flathashmap
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlc_flathashmap-purpose"> Purpose</a>
25/// * <a href="#bdlc_flathashmap-classes"> Classes </a>
26/// * <a href="#bdlc_flathashmap-description"> Description </a>
27/// * <a href="#bdlc_flathashmap-performance-caveats"> Performance Caveats </a>
28/// * <a href="#bdlc_flathashmap-interface-differences-with-unordered_map"> Interface Differences with unordered_map </a>
29/// * <a href="#bdlc_flathashmap-load-factor-and-resizing"> Load Factor and Resizing </a>
30/// * <a href="#bdlc_flathashmap-requirements-on-key-hash-and-equal"> Requirements on KEY, HASH, and EQUAL </a>
31/// * <a href="#bdlc_flathashmap-iterator-pointer-and-reference-invalidation"> Iterator, Pointer, and Reference Invalidation </a>
32/// * <a href="#bdlc_flathashmap-exception-safety"> Exception Safety </a>
33/// * <a href="#bdlc_flathashmap-move-semantics-in-c-03"> Move Semantics in C++03 </a>
34/// * <a href="#bdlc_flathashmap-usage"> Usage </a>
35/// * <a href="#bdlc_flathashmap-example-1-gathering-document-statistics"> Example 1: Gathering Document Statistics </a>
36///
37/// # Purpose {#bdlc_flathashmap-purpose}
38/// Provide an open-addressed unordered map container.
39///
40/// # Classes {#bdlc_flathashmap-classes}
41///
42/// - bdlc::FlatHashMap: open-addressed unordered map container
43///
44/// @see bdlc_flathashtable, bdlc_flathashset
45///
46/// # Description {#bdlc_flathashmap-description}
47/// This component defines a single class template,
48/// `bdlc::FlatHashMap`, that implements an open-addressed unordered map of
49/// items with unique keys.
50///
51/// Unordered maps are useful in situations when there is no meaningful way to
52/// order key values, when the order of the keys is irrelevant to the problem
53/// domain, or (even if there is a meaningful ordering) the value of ordering
54/// the keys is outweighed by the higher performance provided by unordered maps
55/// (compared to ordered maps). On platforms that support relevant SIMD
56/// instructions (e.g., SSE2), `bdlc::FlatHashMap` generally exhibits better
57/// performance than `bsl::unordered_map`.
58///
59/// An instantiation of `bdlc::FlatHashMap` is an allocator-aware,
60/// value-semantic type whose salient attributes are the collection of
61/// `KEY-VALUE` pairs contained, without regard to order. An instantiation may
62/// be provided with custom hash and key-equality functors, but those are not
63/// salient attributes. In particular, when comparing element values for
64/// equality between two different `bdlc::FlatHashMap` objects, the elements are
65/// compared using `operator==`.
66///
67/// The implemented data structure is inspired by Google's @ref flat_hash_map
68/// CppCon presentations (available on YouTube). The implementation draws from
69/// Google's open source `raw_hash_set.h` file at:
70/// https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal.
71///
72/// ## Performance Caveats {#bdlc_flathashmap-performance-caveats}
73///
74///
75/// `bdlc::FlatHashMap` is recommended for Intel platforms *only* (i.e., Linux
76/// and Windows, and pre-ARM Macs); on platforms using other processors (i.e.,
77/// Sun and AIX), `bdlc::FlatHashMap` may have slower performance than
78/// `bsl::unordered_map`. However, note that `bdlc::FlatHashMap` will use
79/// significantly less memory than `bsl::unordered_map` on *all* platforms.
80/// Given the Intel-only performance caveat, it is recommended to benchmark
81/// before using `bdlc::FlatHashMap` -- particularly on non-Intel production
82/// environments.
83///
84/// ## Interface Differences with unordered_map {#bdlc_flathashmap-interface-differences-with-unordered_map}
85///
86///
87/// A `bdlc::FlatHashMap` meets most of the requirements of an unordered
88/// associative container with forward iterators in the C++11 Standard [23.2.5].
89/// It does not have the bucket interface, and locations of elements may change
90/// when the container is modified (and therefore iterators become invalid too).
91/// Allocator use follows BDE style, and the various allocator propagation
92/// attributes are not present (e.g., the allocator trait
93/// @ref propagate_on_container_copy_assignment ). The maximum load factor of the
94/// container (the ratio of size to capacity) is maintained by the container
95/// itself and is not settable (the maximum load factor is implementation
96/// defined and fixed).
97///
98/// ## Load Factor and Resizing {#bdlc_flathashmap-load-factor-and-resizing}
99///
100///
101/// An invariant of `bdlc::FlatHashMap` is that
102/// `0 <= load_factor() <= max_load_factor() <= 1.0`. Any operation that would
103/// result in `load_factor() > max_load_factor()` for a `bdlc::FlatHashMap`
104/// causes the capacity to increase. This resizing allocates new memory, copies
105/// or moves all elements to the new memory, and reclaims the original memory.
106/// The transfer of elements involves rehashing each element to determine its
107/// new location. As such, all iterators, pointers, and references to elements
108/// of the `bdlc::FlatHashMap` are invalidated on a resize.
109///
110/// ## Requirements on KEY, HASH, and EQUAL {#bdlc_flathashmap-requirements-on-key-hash-and-equal}
111///
112///
113/// The template parameter type `KEY` must be copy or move constructible. The
114/// template parameter types `HASH` and `EQUAL` must be default and copy
115/// constructible function objects.
116///
117/// `HASH` must support a function-call operator compatible with the following
118/// statements for an object `key` of type `KEY`:
119/// @code
120/// HASH hash;
121/// bsl::size_t result = hash(key);
122/// @endcode
123///
124/// `EQUAL` must support a function-call operator compatible with the
125/// following statements for objects `key1` and `key2` of type `KEY`:
126/// @code
127/// EQUAL equal;
128/// bool result = equal(key1, key2);
129/// @endcode
130/// where the definition of the called function defines an equivalence
131/// relationship on keys that is both reflexive and transitive.
132///
133/// `HASH` and `EQUAL` function objects are further constrained: if the
134/// comparator determines that two values are equal, the hasher must produce the
135/// same hash value for each.
136///
137/// ## Iterator, Pointer, and Reference Invalidation {#bdlc_flathashmap-iterator-pointer-and-reference-invalidation}
138///
139///
140/// Any change in capacity of a `bdlc::FlatHashMap` invalidates all pointers,
141/// references, and iterators. A `bdlc::FlatHashMap` manipulator that erases an
142/// element invalidates all pointers, references, and iterators to the erased
143/// element.
144///
145/// ## Exception Safety {#bdlc_flathashmap-exception-safety}
146///
147///
148/// A `bdlc::FlatHashMap` is exception neutral, and all of the methods of
149/// `bdlc::FlatHashMap` provide the basic exception safety guarantee (see
150/// {@ref bsldoc_glossary |Basic Guarantee}).
151///
152/// ## Move Semantics in C++03 {#bdlc_flathashmap-move-semantics-in-c-03}
153///
154///
155/// Move-only types are supported by `bdlc::FlatHashMap` on C++11, and later,
156/// platforms only (where `BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES` is defined),
157/// and are not supported on C++03 platforms. Unfortunately, in C++03, there
158/// are user-defined types where a `bslmf::MovableRef` will not safely degrade
159/// to an lvalue reference when a move constructor is not available (types
160/// providing a constructor template taking any type), so
161/// `bslmf::MovableRefUtil::move` cannot be used directly on a user-supplied
162/// template parameter type.
163///
164/// ## Usage {#bdlc_flathashmap-usage}
165///
166///
167/// In this section we show intended use of this component.
168///
169/// ### Example 1: Gathering Document Statistics {#bdlc_flathashmap-example-1-gathering-document-statistics}
170///
171///
172/// Suppose one wished to gather statistics on the words appearing in a large
173/// set of documents on disk or in a database. Gathering those statistics is
174/// intrusive (as one is competing for access to the documents with the regular
175/// users) and must be done as quickly as possible. Moreover, the set of unique
176/// words appearing in those documents may be high. The English language has in
177/// excess of a million words (albeit many appear infrequently), and, if the
178/// documents contain serial numbers, or Social Security numbers, or chemical
179/// formulas, etc., then the `O[log(n)]` insertion time of ordered maps may well
180/// be inadequate. An unordered map, having an `O[1]` typical insertion cost,
181/// is a viable alternative.
182///
183/// This example illustrates the use of `bdlc::FlatHashMap` to gather one simple
184/// statistic (counts of unique words) on a portion of a single document. To
185/// avoid irrelevant details of acquiring the data, the data is stored in static
186/// arrays:
187/// @code
188/// static char document[] =
189/// " IN CONGRESS, July 4, 1776.\n"
190/// "\n"
191/// " The unanimous Declaration of the thirteen united States of America,\n"
192/// "\n"
193/// " When in the Course of human events, it becomes necessary for one\n"
194/// " people to dissolve the political bands which have connected them with\n"
195/// " another, and to assume among the powers of the earth, the separate\n"
196/// " and equal station to which the Laws of Nature and of Nature's G-d\n"
197/// " entitle them, a decent respect to the opinions of mankind requires\n"
198/// " that they should declare the causes which impel them to the\n"
199/// " separation. We hold these truths to be self-evident, that all men\n"
200/// " are created equal, that they are endowed by their Creator with\n"
201/// " certain unalienable Rights, that among these are Life, Liberty and\n"
202/// " the pursuit of Happiness. That to secure these rights, Governments\n"
203/// " are instituted among Men, deriving their just powers from the consent\n"
204/// " of the governed, That whenever any Form of Government becomes\n";
205/// @endcode
206/// First, we define an alias to make our code more comprehensible:
207/// @code
208/// typedef bdlc::FlatHashMap<bsl::string, int> WordTally;
209/// @endcode
210/// Next, we create an (empty) flat hash map to hold our word tallies:
211/// @code
212/// WordTally wordTally;
213/// @endcode
214/// Then, we define the set of characters that define word boundaries:
215/// @code
216/// const char *delimiters = " \n\t,:;.()[]?!/";
217/// @endcode
218/// Next, we extract the words from our document. Note that `strtok` modifies
219/// the document array (which was not made `const`).
220///
221/// For each iteration of the loop, a map entry matching the key value parsed by
222/// `strtok` is obtained. On the first occurrence of a word, the map has no
223/// such entry, so one is created with a default value of the mapped value (0,
224/// just what we want in this case) and inserted into the map where it is found
225/// on any subsequent occurrences of the word. The `operator[]` method returns
226/// a reference providing modifiable access to the mapped value. Here, we apply
227/// the `++` operator to that reference to maintain a tally for the word:
228/// @code
229/// for (char *cur = strtok(document, delimiters);
230/// cur;
231/// cur = strtok(NULL, delimiters)) {
232/// ++wordTally[bsl::string(cur)];
233/// }
234/// @endcode
235/// Now that the data has been (quickly) gathered, we can indulge in analysis
236/// that is more time consuming. For example, we can define a comparison
237/// function, copy the data to another container (e.g., `bsl::vector`), sort the
238/// entries, and determine the 10 most commonly used words in the given
239/// documents:
240/// @code
241/// /// Assignable equivalent to 'WordTally::value_type'. Note that
242/// /// 'bsl::vector' requires assignable types.
243/// typedef bsl::pair<bsl::string, int> WordTallyEntry;
244///
245/// struct WordTallyEntryCompare {
246/// static bool lessThan(const WordTallyEntry& a,
247/// const WordTallyEntry& b) {
248/// return a.second < b.second;
249/// }
250/// static bool greaterThan(const WordTallyEntry& a,
251/// const WordTallyEntry& b) {
252/// return a.second > b.second;
253/// }
254/// };
255///
256/// bsl::vector<WordTallyEntry> array(wordTally.cbegin(), wordTally.cend());
257///
258/// assert(10 <= array.size());
259///
260/// bsl::partial_sort(array.begin(),
261/// array.begin() + 10,
262/// array.end(),
263/// WordTallyEntryCompare::greaterThan);
264/// @endcode
265/// Notice that @ref partial_sort suffices here since we seek only the 10 most used
266/// words, not a complete distribution of word counts.
267///
268/// Finally, we print the sorted portion of `array`:
269/// @code
270/// for (bsl::vector<WordTallyEntry>::const_iterator cur = array.begin(),
271/// end = cur + 10;
272/// end != cur; ++cur) {
273/// printf("%-10s %4d\n", cur->first.c_str(), cur->second);
274/// }
275/// @endcode
276/// and standard output shows:
277/// @code
278/// the 13
279/// of 10
280/// to 7
281/// that 4
282/// are 4
283/// and 4
284/// which 3
285/// these 3
286/// them 3
287/// among 3
288/// @endcode
289/// @}
290/** @} */
291/** @} */
292
293/** @addtogroup bdl
294 * @{
295 */
296/** @addtogroup bdlc
297 * @{
298 */
299/** @addtogroup bdlc_flathashmap
300 * @{
301 */
302
303#include <bdlscm_version.h>
304
305#include <bdlc_flathashtable.h>
306
308#include <bslalg_swaputil.h>
309
311
312#include <bslim_printer.h>
313
314#include <bslma_allocator.h>
318
319#include <bslmf_addconst.h>
320#include <bslmf_enableif.h>
321#include <bslmf_isconvertible.h>
322#include <bslmf_movableref.h>
323#include <bslmf_util.h> // 'forward(V)'
324
325#include <bsls_assert.h>
327#include <bsls_objectbuffer.h>
328#include <bsls_platform.h>
329#include <bsls_util.h> // 'forward<T>(V)'
330
331#include <bslstl_equalto.h>
332#include <bslstl_hash.h>
333#include <bslstl_stdexceptutil.h>
334
335#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
336#include <bsl_initializer_list.h>
337#endif
338#include <bsl_cstddef.h>
339#include <bsl_ostream.h>
340#include <bsl_utility.h>
341
342#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
343// clang-format off
344// Include version that can be compiled with C++03
345// Generated on Mon Jan 13 08:32:17 2025
346// Command line: sim_cpp11_features.pl bdlc_flathashmap.h
347
348# define COMPILING_BDLC_FLATHASHMAP_H
349# include <bdlc_flathashmap_cpp03.h>
350# undef COMPILING_BDLC_FLATHASHMAP_H
351
352// clang-format on
353#else
354
355#if defined(BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER)
356#include <bsl_type_traits.h>
357
358 #ifndef BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES
359 #error Rvalue references curiously absent despite native 'type_traits'.
360 #endif
361
362#endif
363
364
365namespace bdlc {
366
367// FORWARD DECLARATIONS
368template <class KEY,
369 class VALUE,
371 class EQUAL = bsl::equal_to<KEY> >
372class FlatHashMap;
373
374template <class KEY, class VALUE, class HASH, class EQUAL>
375bool operator==(const FlatHashMap<KEY, VALUE, HASH, EQUAL> &lhs,
377
378template <class KEY, class VALUE, class HASH, class EQUAL>
379bool operator!=(const FlatHashMap<KEY, VALUE, HASH, EQUAL> &lhs,
381
382template <class KEY, class VALUE, class HASH, class EQUAL>
385
386 // ============================
387 // struct FlatHashMap_EntryUtil
388 // ============================
389
390/// This templated utility provides methods to construct an `ENTRY` and a
391/// method to extract the key from an `ENTRY`.
392template <class KEY, class VALUE, class ENTRY>
394{
395 // CLASS METHODS
396#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
397 /// Load into the specified `entry` the `ENTRY` value constructed from
398 /// specified `args`, using the specified `allocator` to supply memory.
399 /// `allocator` is ignored if the (template parameter) type `ENTRY` is
400 /// not allocator aware.
401 template <class... ARGS>
402 static void construct(
403 ENTRY *entry,
404 bslma::Allocator *allocator,
405 ARGS&&... args);
406#endif
407
408 /// Load into the specified `entry` the `ENTRY` value comprised of the
409 /// specified `key` and a default constructed `VALUE`, using the
410 /// specified `allocator` to supply memory. `allocator` is ignored if
411 /// the (template parameter) type `ENTRY` is not allocator aware.
412 template <class KEY_TYPE>
413 static void constructFromKey(
414 ENTRY *entry,
415 bslma::Allocator *allocator,
417
418 /// Return the key of the specified `entry`.
419 static const KEY& key(const ENTRY& entry);
420};
421
422 // =================
423 // class FlatHashMap
424 // =================
425
426/// This class template implements a value-semantic container type holding
427/// an unordered map of `KEY-VALUE` pairs having unique keys that provides a
428/// mapping from keys of (template parameter) type `KEY` to their associated
429/// mapped values of (template parameter) type `VALUE`. The (template
430/// parameter) type `HASH` is a functor providing the hash value for `KEY`.
431/// The (template parameter) type `EQUAL` is a functor providing the
432/// equality function for two `KEY` values. See {Requirements on `KEY`,
433/// `HASH`, and `EQUAL`} for more information.
434///
435/// See @ref bdlc_flathashmap
436template <class KEY, class VALUE, class HASH, class EQUAL>
438
439 private:
440 // PRIVATE TYPES
441
442 /// This is the underlying implementation class.
443 typedef FlatHashTable<KEY,
446 VALUE,
448 HASH,
449 EQUAL> ImplType;
450
451 // FRIENDS
452 friend bool operator==<>(const FlatHashMap&, const FlatHashMap&);
453 friend bool operator!=<>(const FlatHashMap&, const FlatHashMap&);
454
455 // The following verbose declaration is required by the xlC 12.1 compiler.
456 template <class K, class V, class H, class E>
458
459 public:
460 // PUBLIC TYPES
462
463 typedef KEY key_type;
464 typedef VALUE mapped_type;
465 typedef bsl::size_t size_type;
466 typedef bsl::ptrdiff_t difference_type;
467 typedef EQUAL key_compare;
468 typedef HASH hasher;
472 typedef const value_type* const_pointer;
473 typedef typename ImplType::iterator iterator;
475
476 private:
477 // DATA
478 ImplType d_impl; // underlying flat hash table used by this flat hash map
479
480 public:
481 // CREATORS
482
483 /// Create an empty `FlatHashMap` object. Optionally specify a
484 /// `capacity` indicating the minimum initial size of the underlying
485 /// array of entries of this container. If `capacity` is not supplied
486 /// or is 0, no memory is allocated. Optionally specify a `hash`
487 /// functor used to generate the hash values associated with the keys of
488 /// elements in this container. If `hash` is not supplied, a
489 /// default-constructed object of the (template parameter) type `HASH`
490 /// is used. Optionally specify an equality functor `equal` used to
491 /// determine whether the keys of two elements are equivalent. If
492 /// `equal` is not supplied, a default-constructed object of the
493 /// (template parameter) type `EQUAL` is used. Optionally specify a
494 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
495 /// supplied or is 0, the currently installed default allocator is used.
496 FlatHashMap();
497 explicit FlatHashMap(bslma::Allocator *basicAllocator);
498 explicit FlatHashMap(bsl::size_t capacity);
499 FlatHashMap(bsl::size_t capacity, bslma::Allocator *basicAllocator);
500 FlatHashMap(bsl::size_t capacity,
501 const HASH& hash,
502 bslma::Allocator *basicAllocator = 0);
503 FlatHashMap(bsl::size_t capacity,
504 const HASH& hash,
505 const EQUAL& equal,
506 bslma::Allocator *basicAllocator = 0);
507
508 /// Create a `FlatHashMap` object initialized by insertion of the values
509 /// from the input iterator range specified by `first` through `last`
510 /// (including `first`, excluding `last`). Optionally specify a
511 /// `capacity` indicating the minimum initial size of the underlying
512 /// array of entries of this container. If `capacity` is not supplied
513 /// or is 0, no memory is allocated. Optionally specify a `hash`
514 /// functor used to generate hash values associated with the keys of the
515 /// elements in this container. If `hash` is not supplied, a
516 /// default-constructed object of the (template parameter) type `HASH`
517 /// is used. Optionally specify an equality functor `equal` used to
518 /// determine whether the keys of two elements are equivalent. If
519 /// `equal` is not supplied, a default-constructed object of the
520 /// (template parameter) type `EQUAL` is used. Optionally specify a
521 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
522 /// supplied or is 0, the currently installed default allocator is used.
523 ///
524 /// \pre The behavior is undefined unless `first` and `last` refer to a
525 /// sequence of valid values where `first` is at a position at or before `last`.
526 ///
527 /// \note Note that if a member of the input sequence has an
528 /// equivalent key to an earlier member, the later member will not be
529 /// inserted.
530 template <class INPUT_ITERATOR>
531 FlatHashMap(INPUT_ITERATOR first,
532 INPUT_ITERATOR last,
533 bslma::Allocator *basicAllocator = 0);
534 template <class INPUT_ITERATOR>
535 FlatHashMap(INPUT_ITERATOR first,
536 INPUT_ITERATOR last,
537 bsl::size_t capacity,
538 bslma::Allocator *basicAllocator = 0);
539 template <class INPUT_ITERATOR>
540 FlatHashMap(INPUT_ITERATOR first,
541 INPUT_ITERATOR last,
542 bsl::size_t capacity,
543 const HASH& hash,
544 bslma::Allocator *basicAllocator = 0);
545 template <class INPUT_ITERATOR>
546 FlatHashMap(INPUT_ITERATOR first,
547 INPUT_ITERATOR last,
548 bsl::size_t capacity,
549 const HASH& hash,
550 const EQUAL& equal,
551 bslma::Allocator *basicAllocator = 0);
552
553#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
554 /// Create a `FlatHashMap` object initialized by insertion of the
555 /// specified `values`. Optionally specify a `capacity` indicating the
556 /// minimum initial size of the underlying array of entries of this
557 /// container. If `capacity` is not supplied or is 0, no memory is
558 /// allocated. Optionally specify a `hash` functor used to generate
559 /// hash values associated with the keys of elements in this container.
560 /// If `hash` is not supplied, a default-constructed object of the
561 /// (template parameter) type `HASH` is used. Optionally specify an
562 /// equality functor `equal` used to determine whether the keys of two
563 /// elements are equivalent. If `equal` is not supplied, a
564 /// default-constructed object of the (template parameter) type `EQUAL`
565 /// is used. Optionally specify a `basicAllocator` used to supply
566 /// memory. If `basicAllocator` is not supplied or is 0, the currently installed default allocator is used.
567 ///
568 /// \note Note that if a member of
569 /// `values` has an equivalent key to an earlier member, the later
570 /// member will not be inserted.
571 FlatHashMap(bsl::initializer_list<value_type> values,
572 bslma::Allocator *basicAllocator = 0);
573 FlatHashMap(bsl::initializer_list<value_type> values,
574 bsl::size_t capacity,
575 bslma::Allocator *basicAllocator = 0);
576 FlatHashMap(bsl::initializer_list<value_type> values,
577 bsl::size_t capacity,
578 const HASH& hash,
579 bslma::Allocator *basicAllocator = 0);
580 FlatHashMap(bsl::initializer_list<value_type> values,
581 bsl::size_t capacity,
582 const HASH& hash,
583 const EQUAL& equal,
584 bslma::Allocator *basicAllocator = 0);
585#endif
586
587 /// Create a `FlatHashMap` object having the same value, hasher, and
588 /// equality comparator as the specified `original` object. Optionally
589 /// specify a `basicAllocator` used to supply memory. If
590 /// `basicAllocator` is not specified or is 0, the currently installed
591 /// default allocator is used.
592 FlatHashMap(const FlatHashMap& original,
593 bslma::Allocator *basicAllocator = 0);
594
595 /// Create a `FlatHashMap` object having the same value, hasher,
596 /// equality comparator, and allocator as the specified `original`
597 /// object. The contents of `original` are moved (in constant time) to
598 /// this object, `original` is left in a (valid) unspecified state, and
599 /// no exceptions will be thrown.
601
602 /// Create a `FlatHashMap` object having the same value, hasher, and
603 /// equality comparator as the specified `original` object, using the
604 /// specified `basicAllocator` to supply memory. If `basicAllocator` is
605 /// 0, the currently installed default allocator is used. The allocator
606 /// of `original` remains unchanged. If `original` and the newly
607 /// created object have the same allocator then the contents of
608 /// `original` are moved (in constant time) to this object, `original`
609 /// is left in a (valid) unspecified state, and no exceptions will be
610 /// thrown; otherwise, `original` is unchanged (and an exception may be
611 /// thrown).
613 bslma::Allocator *basicAllocator);
614
615 /// Destroy this object and each of its elements.
616 ~FlatHashMap();
617
618 // MANIPULATORS
619
620 /// Assign to this object the value, hasher, and equality functor of the
621 /// specified `rhs` object, and return a reference providing modifiable
622 /// access to this object.
623 FlatHashMap& operator=(const FlatHashMap& rhs);
624
625 /// Assign to this object the value, hasher, and equality comparator of
626 /// the specified `rhs` object, and return a reference providing
627 /// modifiable access to this object. If this object and `rhs` use the
628 /// same allocator the contents of `rhs` are moved (in constant time) to
629 /// this object. `rhs` is left in a (valid) unspecified state.
631
632#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
633 /// Assign to this object the value resulting from first clearing this
634 /// map and then inserting each object in the specified `values`
635 /// initializer list, ignoring those objects having a value whose key is
636 /// equivalent to that which appears earlier in the list; return a
637 /// reference providing modifiable access to this object. This method
638 /// requires that the (template parameter) type `KEY` be
639 /// `copy-insertable` into this map (see {Requirements on `KEY`, `HASH`,
640 /// and `EQUAL`}).
641 FlatHashMap& operator=(bsl::initializer_list<value_type> values);
642#endif
643
644 /// Return a reference providing modifiable access to the mapped value
645 /// associated with the specified `key` in this map. If this map does
646 /// not already contain an element having `key`, insert an element with
647 /// the `key` and a default-constructed `VALUE`, and return a reference
648 /// to the newly mapped value. If `key` is movable, `key` is left in a
649 /// (valid) unspecified state.
650 VALUE& operator[](const KEY& key);
651
652 /// Return a reference providing modifiable access to the mapped value
653 /// associated with the specified `key` in this map. If this map does
654 /// not already contain an element having `key`, insert an element with
655 /// the `key` and a default-constructed `VALUE`, and return a reference
656 /// to the newly mapped value. If `key` is movable, `key` is left in a
657 /// (valid) unspecified state.
659
660#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
661#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_PAIR_PIECEWISE_CONSTRUCTOR
662 /// Return a reference providing modifiable access to the mapped value
663 /// associated with the a key equivalent to the specified `key` in this
664 /// map. If this map does not already contain an element eqivalent to
665 /// `key`, insert an element with the KEY constructed from
666 /// `std::forward<LOOKUP_KEY>(k)` and a default-constructed `VALUE`, and
667 /// return a reference to the newly mapped value.
668 template <class LOOKUP_KEY>
669 typename bsl::enable_if<
670 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
671 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
672 , VALUE&>::type
673 operator[](LOOKUP_KEY&& key)
674 {
675 return try_emplace(
676 BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key)).first->second;
677 }
678#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_PAIR_PIECEWISE_CONSTRUCTOR
679#endif
680
681 /// Return a reference providing modifiable access to the mapped value
682 /// associated with the specified `key` in this map, if such an entry
683 /// exists; otherwise throw a `std::out_of_range` exception.
684 ///
685 /// \note Note that this method is not exception-neutral.
686 VALUE& at(const KEY& key);
687
688 /// Return a reference providing modifiable access to the mapped value
689 /// associated with a key that is equivalent to the specified `key` in this
690 /// map, if such an entry exists; otherwise throw a `std::out_of_range` exception.
691 ///
692 /// \note Note that this method is not exception-neutral.
693 template <class LOOKUP_KEY>
694 typename bsl::enable_if<
695 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
696 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
697 , VALUE&>::type
698 at(const LOOKUP_KEY& key)
699 {
700 // Note: implemented inline due to Sun CC compilation error.
701
702 iterator iter = find(key);
703 if (iter == end()) {
704 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
705 "FlatHashMap::at(LOOKUP_KEY): invalid key_value");
706 }
707 return iter->second;
708 }
709
710 /// Remove all elements from this map.
711 /// \note Note that this map will be empty
712 /// after calling this method, but allocated memory may be retained for
713 /// future use. See the `capacity` method.
714 void clear();
715
716 /// Return a pair of iterators defining the sequence of modifiable
717 /// elements in this map having the specified `key`, where the first
718 /// iterator is positioned at the start of the sequence and the second
719 /// iterator is positioned one past the end of the sequence. If this
720 /// map contains no elements having a key equivalent to `key`, then the two returned iterators will have the same value.
721 ///
722 /// \note Note that since a
723 /// map maintains unique keys, the range will contain at most one
724 /// element.
725 bsl::pair<iterator, iterator> equal_range(const KEY& key);
726
727 /// Return a pair of iterators defining the sequence of modifiable
728 /// elements in this map having a key equivalent to the specified `key`,
729 /// where the first iterator is positioned at the start of the sequence and
730 /// the second iterator is positioned one past the end of the sequence. If
731 /// this map contains no elements having a key equivalent to `key`, then the two returned iterators will have the same value.
732 ///
733 /// \note Note that since a
734 /// map maintains unique keys, the range will contain at most one
735 /// element.
736 template <class LOOKUP_KEY>
737 typename bsl::enable_if<
738 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
739 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
741 equal_range(const LOOKUP_KEY& key)
742 {
743 // Note: implemented inline due to Sun CC compilation error.
744
745 return d_impl.equal_range(key);
746 }
747
748#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
749 /// Insert into this map a newly-created `value_type` object,
750 /// constructed by forwarding `get_allocator()` (if required) and the
751 /// specified (variable number of) `args` to the corresponding
752 /// constructor of `value_type`, if a key equivalent to such a value
753 /// does not already exist in this map; otherwise, this method has no
754 /// effect (other than possibly creating a temporary `value_type`
755 /// object). Return a pair whose `first` member is an iterator
756 /// referring to the (possibly newly created and inserted) object in
757 /// this map whose key is equivalent to that of an object constructed
758 /// from `args`, and whose `second` member is `true` if a new value was
759 /// inserted, and `false` if an equivalent key was already present.
760 /// This method requires that the (template parameter) types `KEY` and
761 /// `VALUE` both be `emplace-constructible` from `args` (see
762 /// {Requirements on `value_type`}).
763 template <class... ARGS>
765
766 /// Insert into this map a newly-created `value_type` object,
767 /// constructed by forwarding `get_allocator()` (if required) and the
768 /// specified (variable number of) `args` to the corresponding
769 /// constructor of `value_type`, if a key equivalent to such a value
770 /// does not already exist in this map; otherwise, this method has no
771 /// effect (other than possibly creating a temporary `value_type`
772 /// object). Return an iterator referring to the (possibly newly
773 /// created and inserted) object in this map whose key is equivalent to
774 /// that of an object constructed from `args`. The average and worst
775 /// case complexity of this operation is not affected by the specified
776 /// `hint`. This method requires that the (template parameter) types
777 /// `KEY` and `VALUE` both be `emplace-constructible` from `args` (see {Requirements on `value_type`}).
778 ///
779 /// \pre The behavior is undefined unless
780 /// `hint` is an iterator in the range `[begin() .. end()]` (both endpoints included).
781 ///
782 /// \note Note that `hint` is ignored (other than
783 /// possibly asserting its validity in some build modes).
784 template <class... ARGS>
785 iterator emplace_hint(const_iterator hint, ARGS&&... args);
786#endif
787
788 /// Remove from this map the element whose key is equal to the specified
789 /// `key`, if it exists, and return 1; otherwise (there is no element
790 /// having `key` in this map), return 0 with no other effect. This
791 /// method invalidates all iterators and references to the removed
792 /// element.
793 bsl::size_t erase(const KEY& key);
794
795#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
796 /// Remove from this map the element whose key is equivalent to the
797 /// specified `key`, if it exists, and return 1; otherwise (there is no
798 /// element equivalent to `key` in this map), return 0 with no other effect.
799 /// This method invalidates all iterators and references to the removed
800 /// element.
801 template <class LOOKUP_KEY>
802 typename bsl::enable_if<
803 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
804 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
805 , bsl::size_t>::type
806 erase(LOOKUP_KEY&& key)
807 {
808 return d_impl.erase(key);
809 }
810#endif
811
812 /// Remove from this map the element at the specified `position`, and
813 /// return an iterator referring to the modifiable element immediately
814 /// following the removed element, or to the past-the-end position if
815 /// the removed element was the last element in the sequence of elements
816 /// maintained by this map. This method invalidates all iterators and references to the removed element.
817 ///
818 /// \pre The behavior is undefined unless
819 /// `position` refers to an element in this map.
820 iterator erase(const_iterator position);
821 iterator erase(iterator position);
822
823 /// Remove from this map the elements starting at the specified `first`
824 /// position up to, but not including, the specified `last` position,
825 /// and return an iterator referencing the same element as `last`. This
826 /// method invalidates all iterators and references to the removed elements.
827 ///
828 /// \pre The behavior is undefined unless `first` and `last` are
829 /// valid iterators on this map, and the `first` position is at or
830 /// before the `last` position in the iteration sequence provided by
831 /// this container.
833
834 /// Return an iterator referring to the modifiable element in this map
835 /// having the specified `key`, or `end()` if no such entry exists in
836 /// this map.
837 iterator find(const KEY& key);
838
839 /// Return an `iterator` referring to the modifiable element in this map
840 /// having the key equivalent to the specified `key`, or `end()` if no such
841 /// entry exists in this map.
842 template <class LOOKUP_KEY>
843 typename bsl::enable_if<
844 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
845 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
846 , iterator>::type
847 find(const LOOKUP_KEY& key)
848 {
849 // Note: implemented inline due to Sun CC compilation error.
850
851 return iterator(d_impl.find(key));
852 }
853
854#if defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION < 0x5130
855 template <class VALUE_TYPE>
857#elif !defined(BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER)
858 template <class VALUE_TYPE>
861#else
862 /// Insert the specified `value` into this map if the key of `value`
863 /// does not already exist in this map; otherwise, this method has no
864 /// effect. Return a `pair` whose `first` member is an iterator
865 /// referring to the (possibly newly inserted) modifiable element in
866 /// this map whose key is equivalent to that of the element to be
867 /// inserted, and whose `second` member is `true` if a new element was
868 /// inserted, and `false` if an element with an equivalent key was
869 /// already present.
870 template <class VALUE_TYPE>
871 typename bsl::enable_if<bsl::is_constructible<value_type,
872 VALUE_TYPE&&>::value,
874#endif
876 {
877 // Note that some compilers require functions declared with 'enable_if'
878 // to be defined inline.
879
880 return d_impl.insert(BSLS_COMPILERFEATURES_FORWARD(VALUE_TYPE, value));
881 }
882
883#if defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION < 0x5130
884 template <class VALUE_TYPE>
886#elif !defined(BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER)
887 template <class VALUE_TYPE>
889 iterator>::type
890#else
891 /// Insert the specified `value` into this map if the key of `value`
892 /// does not already exist in this map; otherwise, this method has no
893 /// effect. Return an iterator referring to the (possibly newly
894 /// inserted) modifiable element in this map whose key is equivalent to
895 /// that of the element to be inserted. The supplied `const_iterator`
896 /// is ignored.
897 template <class VALUE_TYPE>
898 typename bsl::enable_if<bsl::is_constructible<value_type,
899 VALUE_TYPE&&>::value,
900 iterator>::type
901#endif
903 BSLS_COMPILERFEATURES_FORWARD_REF(VALUE_TYPE) value)
904 {
905 // Note that some compilers require functions declared with 'enable_if'
906 // to be defined inline.
907
908 return d_impl.insert(BSLS_COMPILERFEATURES_FORWARD(VALUE_TYPE,
909 value)).first;
910 }
911
912 /// Insert into this map the value of each element in the input iterator
913 /// range specified by `first` through `last` (including `first`, excluding `last`).
914 ///
915 /// \pre The behavior is undefined unless `first` and
916 /// `last` refer to a sequence of valid values where `first` is at a position at or before `last`.
917 ///
918 /// \note Note that if the key of a member of
919 /// the input sequence is equivalent to the key of an earlier member,
920 /// the later member will not be inserted.
921 template <class INPUT_ITERATOR>
922 void insert(INPUT_ITERATOR first, INPUT_ITERATOR last);
923
924#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
925 /// Insert into this map an element having the value of each object in
926 /// the specified `values` initializer list if a value with an
927 /// equivalent key is not already contained in this map. This method
928 /// requires that the (template parameter) type `KEY` be copy-insertable
929 /// (see {Requirements on `KEY`, `HASH`, and `EQUAL`}).
930 void insert(bsl::initializer_list<value_type> values);
931#endif
932
933#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
934
935 /// If this map contains an entry with a key equivalent to the specified
936 /// `key`, assign the specified `obj` to the @ref mapped_type of that entry,
937 /// and return an iterator to that entry and `false`. Otherwise, insert a
938 /// new entry into the map with the and return an iterator to that entry
939 /// and `true`. `obj` is left in a (valid) unspecified state.
940 template<class M>
942
943 /// If this map contains an entry with a key equivalent to the specified
944 /// `key`, assign the specified `obj` to the @ref mapped_type of that entry,
945 /// and return an iterator to that entry and `false`. Otherwise, insert a
946 /// new entry into the map with the and return an iterator to that entry
947 /// and `true`. `obj` is left in a (valid) unspecified state.
948 template<class M>
950 BloombergLP::bslmf::MovableRef<KEY> key, M&& obj);
951
952 /// If this map contains an entry with a key equivalent to the specified
953 /// `key`, assign the specified `obj` to the @ref mapped_type of that entry,
954 /// and return an iterator to that entry and `false`. Otherwise, insert a
955 /// new entry into the map with the and return an iterator to that entry
956 /// and `true`. `obj` is left in a (valid) unspecified state.
957 template <class LOOKUP_KEY, class M>
958 typename bsl::enable_if<
959 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
960 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
962 insert_or_assign(LOOKUP_KEY&& key, M&& obj)
963 {
964 iterator iter = find(key);
965 if (iter != end()) {
966 iter->second = std::forward<M>(obj);
967 return make_pair(iter, false); // RETURN
968 }
969 return emplace(BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key),
971 }
972
973 /// If this map contains an entry with a key equivalent to the specified
974 /// `key`, assign the specified `obj` to the @ref mapped_type of that entry.
975 /// Otherwise, insert a new entry into the map. Return an iterator to the
976 /// inserted or updated entry. `obj` is left in a (valid) unspecified
977 /// state.
978 template <class MAPPED>
979 iterator insert_or_assign(const_iterator, const KEY& key, MAPPED&& obj);
980
981 /// If this map contains an entry with a key equivalent to the specified
982 /// `key`, assign the specified `obj` to the @ref mapped_type of that entry.
983 /// Otherwise, insert a new entry into the map. Return an iterator to the
984 /// inserted or updated entry. `obj` is left in a (valid) unspecified
985 /// state.
986 template <class MAPPED>
988 BloombergLP::bslmf::MovableRef<KEY> key,
989 MAPPED&& obj);
990
991 /// If this map contains an entry with a key equivalent to the specified
992 /// `key`, assign the specified `obj` to the @ref mapped_type of that entry.
993 /// Otherwise, insert a new entry into the map. Return an iterator to the
994 /// inserted or updated entry. `obj` is left in a (valid) unspecified
995 /// state.
996 template <class LOOKUP_KEY, class MAPPED>
997 typename bsl::enable_if<
998 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
999 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1000 , iterator>::type
1001 insert_or_assign(const_iterator, LOOKUP_KEY&& key, MAPPED&& obj)
1002 {
1003 return insert_or_assign(
1004 BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key),
1005 BSLS_COMPILERFEATURES_FORWARD(MAPPED, obj)).first;
1006 }
1007#endif
1008
1009
1010 /// Change the capacity of this map to at least the specified
1011 /// `minimumCapacity`, and redistribute all the contained elements into
1012 /// a new sequence of entries according to their hash values. If
1013 /// `0 == minimumCapacity` and `0 == size()`, the map is returned to the
1014 /// default constructed state. After this call, `load_factor()` will be
1015 /// less than or equal to `max_load_factor()` and all iterators,
1016 /// pointers, and references to elements of this map are invalidated.
1017 void rehash(bsl::size_t minimumCapacity);
1018
1019 /// Change the capacity of this map to at least a capacity that can
1020 /// accommodate the specified `numEntries` (accounting for the load
1021 /// factor invariant), and redistribute all the contained elements into
1022 /// a new sequence of entries according to their hash values. If
1023 /// `0 == numEntries` and `0 == size()`, the map is returned to the
1024 /// default constructed state. After this call, `load_factor()` will be
1025 /// less than or equal to `max_load_factor()` and all iterators,
1026 /// pointers, and references to elements of this map are invalidated.
1027 ///
1028 /// \note Note that this method is effectively equivalent to:
1029 /// @code
1030 /// rehash(bsl::ceil(numEntries / max_load_factor()))
1031 /// @endcode
1032 void reserve(bsl::size_t numEntries);
1033
1034 /// Remove all elements from this map and release all memory from this
1035 /// map, returning the map to the default constructed state.
1036 void reset();
1037
1038#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1039#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_PAIR_PIECEWISE_CONSTRUCTOR
1040 /// If a key equivalent to the specified `key` already exists in this
1041 /// map, return a pair containing an iterator referring to the existing
1042 /// item, and `false`. Otherwise, insert into this map a newly-created
1043 /// `value_type` object, constructed from `key` and the specified
1044 /// `args`, and return a pair containing an iterator referring to the
1045 /// newly-created entry and `true`. This method requires that the
1046 /// (template parameter) types `KEY` and `VALUE` are
1047 /// `emplace-constructible` from `key` and `args` respectively. For
1048 /// C++03, `VALUE` must also be `copy-constructible`.
1049 template< class... ARGS>
1050 bsl::pair<iterator, bool> try_emplace(const KEY& key, ARGS&&... args);
1051
1052 /// If a key equivalent to the specified `key` already exists in this
1053 /// map, return a pair containing an iterator referring to the existing
1054 /// item and `false`. Otherwise, insert into this map a newly-created
1055 /// `value_type` object, constructed from `std::forward<KEY>(key)` and
1056 /// the specified `args`, and return a pair containing an iterator
1057 /// referring to the newly-created entry, and `true`. This method
1058 /// requires that the (template parameter) types `KEY` and `VALUE` are
1059 /// `emplace-constructible` from `key` and `args` respectively. For
1060 /// C++03, `VALUE` must also be `copy-constructible`.
1061 template <class... ARGS>
1062 bsl::pair<iterator, bool> try_emplace(
1063 BloombergLP::bslmf::MovableRef<KEY> key,
1064 ARGS&&... args);
1065
1066 /// If a key equivalent to the specified `key` already exists in this map
1067 /// return a pair containing an iterator referring to the existing
1068 /// item and `false`. Otherwise, insert into this map a newly-created
1069 /// `value_type` object, constructed from `std::forward<LOOKUP_KEY>(key)`
1070 /// and the specified `args`, and return a pair containing an iterator
1071 /// referring to the newly-created entry, and `true`. This method
1072 /// requires that the (template parameter) types `KEY` and `VALUE` are
1073 /// `emplace-constructible` from `key` and `args` respectively. For
1074 /// C++03, `VALUE` must also be `copy-constructible`.
1075 template <class LOOKUP_KEY, class... ARGS>
1076 typename bsl::enable_if<
1077 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1078 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1080 try_emplace(LOOKUP_KEY&& key, ARGS&&... args)
1081 {
1082 // Note: implemented inline due to Sun CC compilation error.
1083
1084 return d_impl.try_emplace(
1085 BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key),
1086 std::piecewise_construct,
1087 std::forward_as_tuple(BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key)),
1088 std::forward_as_tuple(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...));
1089 }
1090
1091 /// If a key equivalent to the specified `key` already exists in this
1092 /// map, return an iterator referring to the existing item. Otherwise,
1093 /// insert into this map a newly-created `value_type` object,
1094 /// constructed from `key` and the specified `args`, and return an
1095 /// iterator referring to the newly-created entry. This method requires
1096 /// that the (template parameter) types `KEY` and `VALUE` are
1097 /// `emplace-constructible` from `key` and `args` respectively. For
1098 /// C++03, `VALUE` must also be `copy-constructible`.
1099 template<class... ARGS>
1100 iterator
1101 try_emplace(const_iterator, const KEY& key, ARGS&&... args);
1102
1103 /// If a key equivalent to the specified `key` already exists in this
1104 /// map, return an iterator referring to the existing item. Otherwise,
1105 /// insert into this map a newly-created `value_type` object,
1106 /// constructed from `std::forward<KEY>(key)` and the specified `args`,
1107 /// and return an iterator referring to the newly-created entry. This
1108 /// method requires that the (template parameter) types `KEY` and
1109 /// `VALUE` are `emplace-constructible` from `key` and `args`
1110 /// respectively. For C++03, `VALUE` must also be `copy-constructible`.
1111 template <class... ARGS>
1112 iterator try_emplace(const_iterator,
1113 BloombergLP::bslmf::MovableRef<KEY> key,
1114 ARGS&&... args);
1115
1116 /// If a key equivalent to the specified `key` already exists in this map
1117 /// return an iterator referring to the existing item. Otherwise, insert
1118 /// into this map a newly-created `value_type` object, constructed from
1119 /// `std::forward<LOOKUP_KEY>(key)` and the specified `args`, and return an
1120 /// iterator referring to the newly-created entry. This method requires
1121 /// that the (template parameter) types `KEY` and `VALUE` are
1122 /// `emplace-constructible` from `key` and `args` respectively. For C++03,
1123 /// `VALUE` must also be `copy-constructible`.
1124 template <class LOOKUP_KEY, class... ARGS>
1125 typename bsl::enable_if<
1126 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1127 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1128 , iterator>::type
1129 try_emplace(const_iterator, LOOKUP_KEY&& key, ARGS&&... args)
1130 {
1131 // Note: implemented inline due to Sun CC compilation error.
1132
1133 return d_impl.try_emplace(
1134 BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key),
1135 std::piecewise_construct,
1136 std::forward_as_tuple(
1137 BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, key)),
1138 std::forward_as_tuple(
1139 BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...)
1140 ).first;
1141 }
1142
1143#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_PAIR_PIECEWISE_CONSTRUCTOR
1144#endif
1145
1146 // Iterators
1147
1148 /// Return an iterator to the first element in the sequence of
1149 /// modifiable elements maintained by this map, or the `end` iterator if
1150 /// this map is empty.
1151 iterator begin();
1152
1153 /// Return an iterator to the past-the-end element in the sequence of
1154 /// modifiable elements maintained by this map.
1155 iterator end();
1156
1157 // Aspects
1158
1159 /// Exchange the value of this object as well as its hasher and equality
1160 /// functors with those of the specified `other` object.
1161 ///
1162 /// \pre The behavior is undefined unless this object was created with the same allocator
1163 /// as `other`.
1164 void swap(FlatHashMap& other);
1165
1166 // ACCESSORS
1167
1168 /// Return a reference providing non-modifiable access to the mapped
1169 /// value associated with the specified `key` in this map, if such an
1170 /// entry exists; otherwise throw a `std::out_of_range` exception.
1171 ///
1172 /// \note Note that this method is not exception-neutral.
1173 const VALUE& at(const KEY& key) const;
1174
1175 /// Return a reference providing non-modifiable access to the mapped
1176 /// value associated with a key that is equivalent to the specified `key`
1177 /// in this map, if such an entry exists; otherwise throw a `std::out_of_range` exception.
1178 ///
1179 /// \note Note that this method is not
1180 /// exception-neutral.
1181 template <class LOOKUP_KEY>
1182 typename bsl::enable_if<
1183 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1184 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1185 , const VALUE&>::type
1186 at(const LOOKUP_KEY& key) const
1187 {
1188 // Note: implemented inline due to Sun CC compilation error.
1189
1190 const_iterator iter = find(key);
1191 if (iter == end()) {
1192 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1193 "FlatHashMap::at(LOOKUP_KEY) const: invalid key_value");
1194 }
1195 return iter->second;
1196 }
1197
1198 /// Return the number of elements this map could hold if the load factor
1199 /// were 1.
1200 bsl::size_t capacity() const;
1201
1202 /// Return `true` if this map contains an element having the specified
1203 /// `key`, and `false` otherwise.
1204 bool contains(const KEY& key) const;
1205
1206 /// Return `true` if this map contains an element whose key is equivalent
1207 /// to the specified `key`.
1208 template <class LOOKUP_KEY>
1209 typename bsl::enable_if<
1210 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1211 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1212 , bool>::type
1213 contains(const LOOKUP_KEY& key) const
1214 {
1215 // Note: implemented inline due to Sun CC compilation error.
1216
1217 return find(key) != end();
1218 }
1219
1220 /// Return the number of elements in this map having the specified `key`.
1221 ///
1222 /// \note Note that since a flat hash map maintains unique keys, the
1223 /// returned value will be either 0 or 1.
1224 bsl::size_t count(const KEY& key) const;
1225
1226 /// Return the number of elements in this map having a key equivalent to the specified `key`.
1227 ///
1228 /// \note Note that since a flat hash map maintains unique
1229 /// keys, the returned value will be either 0 or 1.
1230 template <class LOOKUP_KEY>
1231 typename bsl::enable_if<
1232 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1233 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1234 , bsl::size_t >::type
1235 count(const LOOKUP_KEY& key) const
1236 {
1237 // Note: implemented inline due to Sun CC compilation error.
1238
1239 return find(key) != end() ? 1 : 0;
1240 }
1241
1242 /// Return `true` if this map contains no elements, and `false`
1243 /// otherwise.
1244 bool empty() const;
1245
1246 /// Return a pair of `const_iterator`s defining the sequence of elements
1247 /// in this map having the specified `key`, where the first iterator is
1248 /// positioned at the start of the sequence and the second iterator is
1249 /// positioned one past the end of the sequence. If this map contains
1250 /// no elements having a key equivalent to `key`, then the two returned iterators will have the same value.
1251 ///
1252 /// \note Note that since a map maintains
1253 /// unique keys, the range will contain at most one element.
1255 const KEY& key) const;
1256
1257 /// Return a pair of iterators providing non-modifiable access to the
1258 /// sequence of `value_type` objects in this unordered map that are
1259 /// equivalent to the specified `key`, where the first iterator is
1260 /// positioned at the start of the sequence and the second iterator is
1261 /// positioned one past the end of the sequence. If this unordered map
1262 /// contains no `value_type` objects equivalent to `key`, then the two returned iterators will have the same value.
1263 ///
1264 /// \note Note that since an
1265 /// unordered map maintains unique keys, the range will contain at most one
1266 /// element.
1267 template <class LOOKUP_KEY>
1268 typename bsl::enable_if<
1269 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1270 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1272 equal_range(const LOOKUP_KEY& key) const
1273 {
1274 // Note: implemented inline due to Sun CC compilation error.
1275
1276 return d_impl.equal_range(key);
1277 }
1278
1279 /// Return a `const_iterator` referring to the element in this map
1280 /// having the specified `key`, or `end()` if no such entry exists in
1281 /// this map.
1282 const_iterator find(const KEY& key) const;
1283
1284 /// Return a `const_iterator` referring to the element in this map
1285 /// having the specified `key`, or `end()` if no such entry exists in
1286 /// this map.
1287 template <class LOOKUP_KEY>
1288 typename bsl::enable_if<
1289 BloombergLP::bslmf::IsTransparentPredicate<HASH, LOOKUP_KEY>::value
1290 && BloombergLP::bslmf::IsTransparentPredicate<EQUAL,LOOKUP_KEY>::value
1291 , const_iterator>::type
1292 find(const LOOKUP_KEY& key) const
1293 {
1294 // Note: implemented inline due to Sun CC compilation error.
1295
1296 return const_iterator(d_impl.find(key));
1297 }
1298
1299
1300 /// Return (a copy of) the unary hash functor used by this map to
1301 /// generate a hash value (of type `bsl::size_t`) for a `KEY` object.
1302 HASH hash_function() const;
1303
1304 /// Return (a copy of) the binary key-equality functor that returns
1305 /// `true` if the value of two `KEY` objects are equivalent, and `false`
1306 /// otherwise.
1307 EQUAL key_eq() const;
1308
1309 /// Return the current ratio between the number of elements in this
1310 /// container and its capacity.
1311 float load_factor() const;
1312
1313 /// Return the maximum load factor allowed for this map.
1314 /// \note Note that if
1315 /// an insert operation would cause the load factor to exceed
1316 /// `max_load_factor()`, that same insert operation will increase the
1317 /// capacity and rehash the entries of the container (see {Load Factor
1318 /// and Resizing}). Also note that the value returned by
1319 /// @ref max_load_factor is implementation defined and cannot be changed by
1320 /// the user.
1321 float max_load_factor() const;
1322
1323 /// Return the number of elements in this map.
1324 bsl::size_t size() const;
1325
1326 // Iterators
1327
1328 /// Return a `const_iterator` to the first element in the sequence of
1329 /// elements maintained by this map, or the `end` iterator if this map
1330 /// is empty.
1331 const_iterator begin() const;
1332
1333 /// Return a `const_iterator` to the first element in the sequence of
1334 /// elements maintained by this map, or the `end` iterator if this map
1335 /// is empty.
1336 const_iterator cbegin() const;
1337
1338 /// Return a `const_iterator` to the past-the-end element in the
1339 /// sequence of elements maintained by this map.
1340 const_iterator cend() const;
1341
1342 /// Return a `const_iterator` to the past-the-end element in the
1343 /// sequence of elements maintained by this map.
1344 const_iterator end() const;
1345
1346 // Aspects
1347
1348 /// Return the allocator used by this flat hash map to supply memory.
1349 bslma::Allocator *allocator() const;
1350
1351 /// Format this object to the specified output `stream` at the (absolute
1352 /// value of) the optionally specified indentation `level`, and return a
1353 /// reference to the modifiable `stream`. If `level` is specified,
1354 /// optionally specify `spacesPerLevel`, the number of spaces per
1355 /// indentation level for this and all of its nested objects. If
1356 /// `level` is negative, suppress indentation of the first line. If
1357 /// `spacesPerLevel` is negative, format the entire output on one line,
1358 /// suppressing all but the initial indentation (as governed by
1359 /// `level`). If `stream` is not valid on entry, this operation has no
1360 /// effect.
1361 bsl::ostream& print(bsl::ostream& stream,
1362 int level = 0,
1363 int spacesPerLevel = 4) const;
1364};
1365
1366// FREE OPERATORS
1367
1368/// Return `true` if the specified `lhs` and `rhs` objects have the same
1369/// value, and `false` otherwise. Two `FlatHashMap` objects have the same
1370/// value if their sizes are the same and each element contained in one is
1371/// equal to an element of the other. The hash and equality functors are
1372/// not involved in the comparison.
1373template <class KEY, class VALUE, class HASH, class EQUAL>
1374bool operator==(const FlatHashMap<KEY, VALUE, HASH, EQUAL> &lhs,
1375 const FlatHashMap<KEY, VALUE, HASH, EQUAL> &rhs);
1376
1377/// Return `true` if the specified `lhs` and `rhs` objects do not have the
1378/// same value, and `false` otherwise. Two `FlatHashMap` objects do not
1379/// have the same value if their sizes are different or one contains an
1380/// element equal to no element of the other. The hash and equality
1381/// functors are not involved in the comparison.
1382template <class KEY, class VALUE, class HASH, class EQUAL>
1383bool operator!=(const FlatHashMap<KEY, VALUE, HASH, EQUAL> &lhs,
1384 const FlatHashMap<KEY, VALUE, HASH, EQUAL> &rhs);
1385
1386/// Write the value of the specified `map` to the specified output `stream`
1387/// in a single-line format, and return a reference providing modifiable
1388/// access to `stream`. If `stream` is not valid on entry, this operation has no effect.
1389///
1390/// \note Note that this human-readable format is not fully
1391/// specified and can change without notice.
1392template <class KEY, class VALUE, class HASH, class EQUAL>
1393bsl::ostream& operator<<(bsl::ostream& stream,
1395
1396// FREE FUNCTIONS
1397
1398/// Exchange the value, the hasher, and the key-equality functor of the
1399/// specified `a` and `b` objects. This function provides the no-throw
1400/// exception-safety guarantee if the two objects were created with the same
1401/// allocator and the basic guarantee otherwise.
1402template <class KEY, class VALUE, class HASH, class EQUAL>
1405
1406// ============================================================================
1407// TEMPLATE AND INLINE FUNCTION DEFINITIONS
1408// ============================================================================
1409
1410 // ----------------------------
1411 // struct FlatHashMap_EntryUtil
1412 // ----------------------------
1413
1414// CLASS METHODS
1415#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1416template <class KEY, class VALUE, class ENTRY>
1417template <class... ARGS>
1418inline
1420 ENTRY *entry,
1421 bslma::Allocator *allocator,
1422 ARGS&&... args)
1423{
1424 BSLS_ASSERT_SAFE(entry);
1426 entry,
1427 allocator,
1428 BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...);
1429}
1430#endif
1431
1432template <class KEY, class VALUE, class ENTRY>
1433template <class KEY_TYPE>
1434inline
1436 ENTRY *entry,
1437 bslma::Allocator *allocator,
1439{
1440 BSLS_ASSERT_SAFE(entry);
1441
1443
1444 bslma::ConstructionUtil::construct(value.address(), allocator);
1446
1448 entry,
1449 allocator,
1450 BSLS_COMPILERFEATURES_FORWARD(KEY_TYPE, key),
1452}
1453
1454template <class KEY, class VALUE, class ENTRY>
1455inline
1457{
1458 return entry.first;
1459}
1460
1461 // -----------------
1462 // class FlatHashMap
1463 // -----------------
1464
1465// CREATORS
1466template <class KEY, class VALUE, class HASH, class EQUAL>
1467inline
1469: d_impl(0, HASH(), EQUAL())
1470{
1471}
1472
1473template <class KEY, class VALUE, class HASH, class EQUAL>
1474inline
1476 bslma::Allocator *basicAllocator)
1477: d_impl(0, HASH(), EQUAL(), basicAllocator)
1478{
1479}
1480
1481template <class KEY, class VALUE, class HASH, class EQUAL>
1482inline
1484: d_impl(capacity, HASH(), EQUAL())
1485{
1486}
1487
1488template <class KEY, class VALUE, class HASH, class EQUAL>
1489inline
1491 bsl::size_t capacity,
1492 bslma::Allocator *basicAllocator)
1493: d_impl(capacity, HASH(), EQUAL(), basicAllocator)
1494{
1495}
1496
1497template <class KEY, class VALUE, class HASH, class EQUAL>
1498inline
1500 bsl::size_t capacity,
1501 const HASH& hash,
1502 bslma::Allocator *basicAllocator)
1503: d_impl(capacity, hash, EQUAL(), basicAllocator)
1504{
1505}
1506
1507template <class KEY, class VALUE, class HASH, class EQUAL>
1508inline
1510 bsl::size_t capacity,
1511 const HASH& hash,
1512 const EQUAL& equal,
1513 bslma::Allocator *basicAllocator)
1514: d_impl(capacity, hash, equal, basicAllocator)
1515{
1516}
1517
1518template <class KEY, class VALUE, class HASH, class EQUAL>
1519template <class INPUT_ITERATOR>
1520inline
1522 INPUT_ITERATOR first,
1523 INPUT_ITERATOR last,
1524 bslma::Allocator *basicAllocator)
1525: d_impl(0, HASH(), EQUAL(), basicAllocator)
1526{
1527 insert(first, last);
1528}
1529
1530template <class KEY, class VALUE, class HASH, class EQUAL>
1531template <class INPUT_ITERATOR>
1532inline
1534 INPUT_ITERATOR first,
1535 INPUT_ITERATOR last,
1536 bsl::size_t capacity,
1537 bslma::Allocator *basicAllocator)
1538: d_impl(capacity, HASH(), EQUAL(), basicAllocator)
1539{
1540 insert(first, last);
1541}
1542
1543template <class KEY, class VALUE, class HASH, class EQUAL>
1544template <class INPUT_ITERATOR>
1545inline
1547 INPUT_ITERATOR first,
1548 INPUT_ITERATOR last,
1549 bsl::size_t capacity,
1550 const HASH& hash,
1551 bslma::Allocator *basicAllocator)
1552: d_impl(capacity, hash, EQUAL(), basicAllocator)
1553{
1554 insert(first, last);
1555}
1556
1557template <class KEY, class VALUE, class HASH, class EQUAL>
1558template <class INPUT_ITERATOR>
1559inline
1561 INPUT_ITERATOR first,
1562 INPUT_ITERATOR last,
1563 bsl::size_t capacity,
1564 const HASH& hash,
1565 const EQUAL& equal,
1566 bslma::Allocator *basicAllocator)
1567: d_impl(capacity, hash, equal, basicAllocator)
1568{
1569 insert(first, last);
1570}
1571
1572#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1573template <class KEY, class VALUE, class HASH, class EQUAL>
1574inline
1576 bsl::initializer_list<value_type> values,
1577 bslma::Allocator *basicAllocator)
1578: FlatHashMap(values.begin(),
1579 values.end(),
1580 0,
1581 HASH(),
1582 EQUAL(),
1583 basicAllocator)
1584{
1585}
1586
1587template <class KEY, class VALUE, class HASH, class EQUAL>
1588inline
1590 bsl::initializer_list<value_type> values,
1591 bsl::size_t capacity,
1592 bslma::Allocator *basicAllocator)
1593: FlatHashMap(values.begin(),
1594 values.end(),
1595 capacity,
1596 HASH(),
1597 EQUAL(),
1598 basicAllocator)
1599{
1600}
1601
1602template <class KEY, class VALUE, class HASH, class EQUAL>
1603inline
1605 bsl::initializer_list<value_type> values,
1606 bsl::size_t capacity,
1607 const HASH& hash,
1608 bslma::Allocator *basicAllocator)
1609: FlatHashMap(values.begin(),
1610 values.end(),
1611 capacity,
1612 hash,
1613 EQUAL(),
1614 basicAllocator)
1615{
1616}
1617
1618template <class KEY, class VALUE, class HASH, class EQUAL>
1619inline
1621 bsl::initializer_list<value_type> values,
1622 bsl::size_t capacity,
1623 const HASH& hash,
1624 const EQUAL& equal,
1625 bslma::Allocator *basicAllocator)
1626: FlatHashMap(values.begin(),
1627 values.end(),
1628 capacity,
1629 hash,
1630 equal,
1631 basicAllocator)
1632{
1633}
1634#endif
1635
1636template <class KEY, class VALUE, class HASH, class EQUAL>
1637inline
1639 const FlatHashMap& original,
1640 bslma::Allocator *basicAllocator)
1641: d_impl(original.d_impl, basicAllocator)
1642{
1643}
1644
1645template <class KEY, class VALUE, class HASH, class EQUAL>
1646inline
1649: d_impl(bslmf::MovableRefUtil::move(
1650 bslmf::MovableRefUtil::access(original).d_impl))
1651{
1652}
1653
1654template <class KEY, class VALUE, class HASH, class EQUAL>
1655inline
1658 bslma::Allocator *basicAllocator)
1659: d_impl(bslmf::MovableRefUtil::move(
1660 bslmf::MovableRefUtil::access(original).d_impl),
1661 basicAllocator)
1662{
1663}
1664
1665template <class KEY, class VALUE, class HASH, class EQUAL>
1666inline
1670
1671// MANIPULATORS
1672template <class KEY, class VALUE, class HASH, class EQUAL>
1673inline
1676{
1677 d_impl = rhs.d_impl;
1678
1679 return *this;
1680}
1681
1682template <class KEY, class VALUE, class HASH, class EQUAL>
1683inline
1687{
1688 FlatHashMap& lvalue = rhs;
1689
1690 d_impl = bslmf::MovableRefUtil::move(lvalue.d_impl);
1691
1692 return *this;
1693}
1694
1695#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1696template <class KEY, class VALUE, class HASH, class EQUAL>
1697inline
1700 bsl::initializer_list<value_type> values)
1701{
1702 FlatHashMap tmp(values.begin(),
1703 values.end(),
1704 0,
1705 d_impl.hash_function(),
1706 d_impl.key_eq(),
1707 d_impl.allocator());
1708
1709 this->swap(tmp);
1710
1711 return *this;
1712}
1713#endif
1714
1715template <class KEY, class VALUE, class HASH, class EQUAL>
1716inline
1718{
1719 return d_impl[key].second;
1720}
1721
1722template <class KEY, class VALUE, class HASH, class EQUAL>
1723inline
1728
1729template <class KEY, class VALUE, class HASH, class EQUAL>
1730inline
1732{
1733 iterator node = d_impl.find(key);
1734
1735 if (node == d_impl.end()) {
1736 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1737 "FlatHashMap<...>::at(key_type): invalid key value");
1738 }
1739
1740 return node->second;
1741}
1742
1743template <class KEY, class VALUE, class HASH, class EQUAL>
1744inline
1745void
1750
1751template <class KEY, class VALUE, class HASH, class EQUAL>
1755{
1756 return d_impl.equal_range(key);
1757}
1758
1759#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1760template <class KEY, class VALUE, class HASH, class EQUAL>
1761template <class... ARGS>
1762inline
1765{
1766 return d_impl.emplace(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...);
1767}
1768
1769template <class KEY, class VALUE, class HASH, class EQUAL>
1770template <class... ARGS>
1771inline
1774 ARGS&&... args)
1775{
1776 return emplace(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...).first;
1777}
1778#endif
1779
1780
1781template <class KEY, class VALUE, class HASH, class EQUAL>
1783{
1784 return d_impl.erase(key);
1785}
1786
1787template <class KEY, class VALUE, class HASH, class EQUAL>
1788inline
1791{
1792 BSLS_ASSERT_SAFE(position != end());
1793
1794 return d_impl.erase(position);
1795}
1796
1797template <class KEY, class VALUE, class HASH, class EQUAL>
1798inline
1801{
1802 // Note that this overload is necessary to avoid ambiguity when the key is
1803 // an iterator.
1804
1805 BSLS_ASSERT_SAFE(position != end());
1806
1807 return d_impl.erase(position);
1808}
1809
1810template <class KEY, class VALUE, class HASH, class EQUAL>
1813 const_iterator last)
1814{
1815 return d_impl.erase(first, last);
1816}
1817
1818template <class KEY, class VALUE, class HASH, class EQUAL>
1819inline
1822{
1823 return d_impl.find(key);
1824}
1825
1826template <class KEY, class VALUE, class HASH, class EQUAL>
1827template <class INPUT_ITERATOR>
1829 INPUT_ITERATOR last)
1830{
1831 d_impl.insert(first, last);
1832}
1833
1834#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1835template <class KEY, class VALUE, class HASH, class EQUAL>
1836template <class MAPPED>
1837inline
1840 MAPPED&& obj)
1841{
1842 iterator iter = find(key);
1843 if (iter != end()) {
1844 iter->second = std::forward<MAPPED>(obj);
1845 return make_pair(iter, false); // RETURN
1846 }
1847 return emplace(key, BSLS_COMPILERFEATURES_FORWARD(MAPPED, obj));
1848}
1849
1850template <class KEY, class VALUE, class HASH, class EQUAL>
1851template <class MAPPED>
1852inline
1855 BloombergLP::bslmf::MovableRef<KEY> key,
1856 MAPPED&& obj)
1857{
1858 const KEY& lvalue = key;
1859 iterator iter = find(lvalue);
1860 if (iter != end()) {
1861 iter->second = std::forward<MAPPED>(obj);
1862 return make_pair(iter, false); // RETURN
1863 }
1864 return emplace(bslmf::MovableRefUtil::move(lvalue),
1865 BSLS_COMPILERFEATURES_FORWARD(MAPPED, obj));
1866}
1867
1868template <class KEY, class VALUE, class HASH, class EQUAL>
1869template <class MAPPED>
1870inline
1873 const KEY& key,
1874 MAPPED&& obj)
1875{
1876 return insert_or_assign(key,
1877 BSLS_COMPILERFEATURES_FORWARD(MAPPED, obj)).first;
1878}
1879
1880template <class KEY, class VALUE, class HASH, class EQUAL>
1881template <class MAPPED>
1882inline
1886 BloombergLP::bslmf::MovableRef<KEY> key,
1887 MAPPED&& obj)
1888{
1889 const KEY& lvalue = key;
1890 return insert_or_assign(bslmf::MovableRefUtil::move(lvalue),
1891 BSLS_COMPILERFEATURES_FORWARD(MAPPED, obj)).first;
1892}
1893#endif
1894
1895#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1896template <class KEY, class VALUE, class HASH, class EQUAL>
1898 bsl::initializer_list<value_type> values)
1899{
1900 insert(values.begin(), values.end());
1901}
1902#endif
1903
1904template <class KEY, class VALUE, class HASH, class EQUAL>
1905inline
1906void FlatHashMap<KEY, VALUE, HASH, EQUAL>::rehash(bsl::size_t minimumCapacity)
1907{
1908 d_impl.rehash(minimumCapacity);
1909}
1910
1911template <class KEY, class VALUE, class HASH, class EQUAL>
1912inline
1914{
1915 d_impl.reserve(numEntries);
1916}
1917
1918template <class KEY, class VALUE, class HASH, class EQUAL>
1919inline
1921{
1922 d_impl.reset();
1923}
1924
1925#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1926#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_PAIR_PIECEWISE_CONSTRUCTOR
1927template <class KEY, class VALUE, class HASH, class EQUAL>
1928template< class... ARGS>
1929inline
1932 ARGS&&... args)
1933{
1934 return d_impl.try_emplace(
1935 key,
1936 std::piecewise_construct,
1937 std::forward_as_tuple(key),
1938 std::forward_as_tuple(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...));
1939}
1940
1941template <class KEY, class VALUE, class HASH, class EQUAL>
1942template <class... ARGS>
1944FlatHashMap<KEY, VALUE, HASH, EQUAL>::try_emplace(
1945 BloombergLP::bslmf::MovableRef<KEY> key,
1946 ARGS&&... args)
1947{
1948 return d_impl.try_emplace(
1950 std::piecewise_construct,
1951 std::forward_as_tuple(BSLS_COMPILERFEATURES_FORWARD(KEY, key)),
1952 std::forward_as_tuple(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...));
1953}
1954
1955template <class KEY, class VALUE, class HASH, class EQUAL>
1956template<class... ARGS>
1958FlatHashMap<KEY, VALUE, HASH, EQUAL>::try_emplace(const_iterator,
1959 const KEY& key,
1960 ARGS&&... args)
1961{
1962 return d_impl.try_emplace(
1963 key,
1964 std::piecewise_construct,
1965 std::forward_as_tuple(key),
1966 std::forward_as_tuple(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...))
1967 .first;
1968}
1969
1970template <class KEY, class VALUE, class HASH, class EQUAL>
1971template <class... ARGS>
1973FlatHashMap<KEY, VALUE, HASH, EQUAL>::try_emplace(const_iterator,
1974 BloombergLP::bslmf::MovableRef<KEY> key,
1975 ARGS&&... args)
1976{
1977 return d_impl.try_emplace(
1979 std::piecewise_construct,
1980 std::forward_as_tuple(BSLS_COMPILERFEATURES_FORWARD(KEY, key)),
1981 std::forward_as_tuple(BSLS_COMPILERFEATURES_FORWARD(ARGS, args)...))
1982 .first;
1983}
1984#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_PAIR_PIECEWISE_CONSTRUCTOR
1985#endif
1986
1987 // Iterators
1988
1989template <class KEY, class VALUE, class HASH, class EQUAL>
1990inline
1993{
1994 return d_impl.begin();
1995}
1996
1997template <class KEY, class VALUE, class HASH, class EQUAL>
1998inline
2001{
2002 return d_impl.end();
2003}
2004
2005 // Aspects
2006
2007template <class KEY, class VALUE, class HASH, class EQUAL>
2008inline
2010{
2011 BSLS_ASSERT_SAFE(allocator() == other.allocator());
2012
2013 d_impl.swap(other.d_impl);
2014}
2015
2016// ACCESSORS
2017template <class KEY, class VALUE, class HASH, class EQUAL>
2018inline
2019const VALUE& FlatHashMap<KEY, VALUE, HASH, EQUAL>::at(const KEY& key) const
2020{
2021 const_iterator node = d_impl.find(key);
2022
2023 if (node == d_impl.end()) {
2024 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2025 "FlatHashMap<...>::at(key_type) const: invalid key value");
2026 }
2027
2028 return node->second;
2029}
2030
2031template <class KEY, class VALUE, class HASH, class EQUAL>
2032inline
2034{
2035 return d_impl.capacity();
2036}
2037
2038template <class KEY, class VALUE, class HASH, class EQUAL>
2039inline
2041{
2042 return d_impl.contains(key);
2043}
2044
2045template <class KEY, class VALUE, class HASH, class EQUAL>
2046inline
2047bsl::size_t FlatHashMap<KEY, VALUE, HASH, EQUAL>::count(const KEY& key) const
2048{
2049 return d_impl.count(key);
2050}
2051
2052template <class KEY, class VALUE, class HASH, class EQUAL>
2053inline
2055{
2056 return d_impl.empty();
2057}
2058
2059template <class KEY, class VALUE, class HASH, class EQUAL>
2063{
2064 return d_impl.equal_range(key);
2065}
2066
2067template <class KEY, class VALUE, class HASH, class EQUAL>
2068inline
2071{
2072 return d_impl.find(key);
2073}
2074
2075template <class KEY, class VALUE, class HASH, class EQUAL>
2076inline
2078{
2079 return d_impl.hash_function();
2080}
2081
2082template <class KEY, class VALUE, class HASH, class EQUAL>
2083inline
2085{
2086 return d_impl.key_eq();
2087}
2088
2089template <class KEY, class VALUE, class HASH, class EQUAL>
2090inline
2092{
2093 return d_impl.load_factor();
2094}
2095
2096template <class KEY, class VALUE, class HASH, class EQUAL>
2097inline
2099{
2100 return d_impl.max_load_factor();
2101}
2102
2103template <class KEY, class VALUE, class HASH, class EQUAL>
2104inline
2106{
2107 return d_impl.size();
2108}
2109
2110 // Iterators
2111
2112template <class KEY, class VALUE, class HASH, class EQUAL>
2113inline
2116{
2117 return d_impl.begin();
2118}
2119template <class KEY, class VALUE, class HASH, class EQUAL>
2120inline
2123{
2124 return d_impl.cbegin();
2125}
2126
2127template <class KEY, class VALUE, class HASH, class EQUAL>
2128inline
2131{
2132 return d_impl.cend();
2133}
2134
2135template <class KEY, class VALUE, class HASH, class EQUAL>
2136inline
2139{
2140 return d_impl.end();
2141}
2142
2143 // Aspects
2144
2145template <class KEY, class VALUE, class HASH, class EQUAL>
2146inline
2151
2152template <class KEY, class VALUE, class HASH, class EQUAL>
2154 bsl::ostream& stream,
2155 int level,
2156 int spacesPerLevel) const
2157{
2158 if (stream.bad()) {
2159 return stream; // RETURN
2160 }
2161
2162 bslim::Printer printer(&stream, level, spacesPerLevel);
2163
2164 printer.start();
2165
2166 const_iterator iter = begin();
2167 while (iter != end()) {
2168 printer.printValue(*iter);
2169 ++iter;
2170 }
2171
2172 printer.end();
2173
2174 return stream;
2175}
2176
2177} // close package namespace
2178
2179// FREE OPERATORS
2180template <class KEY, class VALUE, class HASH, class EQUAL>
2181inline
2182bool bdlc::operator==(const FlatHashMap<KEY, VALUE, HASH, EQUAL>& lhs,
2183 const FlatHashMap<KEY, VALUE, HASH, EQUAL>& rhs)
2184{
2185 return lhs.d_impl == rhs.d_impl;
2186}
2187
2188template <class KEY, class VALUE, class HASH, class EQUAL>
2189inline
2190bool bdlc::operator!=(const FlatHashMap<KEY, VALUE, HASH, EQUAL>& lhs,
2191 const FlatHashMap<KEY, VALUE, HASH, EQUAL>& rhs)
2192{
2193 return lhs.d_impl != rhs.d_impl;
2194}
2195
2196template <class KEY, class VALUE, class HASH, class EQUAL>
2197inline
2198bsl::ostream& bdlc::operator<<(
2199 bsl::ostream& stream,
2200 const FlatHashMap<KEY, VALUE, HASH, EQUAL>& map)
2201{
2202 return map.print(stream, 0, -1);
2203}
2204
2205// FREE FUNCTIONS
2206template <class KEY, class VALUE, class HASH, class EQUAL>
2207inline
2208void bdlc::swap(FlatHashMap<KEY, VALUE, HASH, EQUAL>& a,
2209 FlatHashMap<KEY, VALUE, HASH, EQUAL>& b)
2210{
2211 bslalg::SwapUtil::swap(&a.d_impl, &b.d_impl);
2212}
2213
2214// ============================================================================
2215// TYPE TRAITS
2216// ============================================================================
2217
2218namespace bslalg {
2219
2220template <class KEY, class VALUE, class HASH, class EQUAL>
2221struct HasStlIterators<bdlc::FlatHashMap<KEY, VALUE, HASH, EQUAL> >
2223};
2224
2225} // close namespace bslalg
2226
2227namespace bslma {
2228
2229template <class KEY, class VALUE, class HASH, class EQUAL>
2230struct UsesBslmaAllocator<bdlc::FlatHashMap<KEY, VALUE, HASH, EQUAL> >
2232};
2233
2234} // close namespace bslma
2235
2236
2237#endif // End C++11 code
2238
2239#endif
2240
2241// ----------------------------------------------------------------------------
2242// Copyright 2020 Bloomberg Finance L.P.
2243//
2244// Licensed under the Apache License, Version 2.0 (the "License");
2245// you may not use this file except in compliance with the License.
2246// You may obtain a copy of the License at
2247//
2248// http://www.apache.org/licenses/LICENSE-2.0
2249//
2250// Unless required by applicable law or agreed to in writing, software
2251// distributed under the License is distributed on an "AS IS" BASIS,
2252// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2253// See the License for the specific language governing permissions and
2254// limitations under the License.
2255// ----------------------------- END-OF-FILE ----------------------------------
2256
2257/** @} */
2258/** @} */
2259/** @} */
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition bdlc_flathashmap.h:437
HASH hasher
Definition bdlc_flathashmap.h:468
const value_type * const_pointer
Definition bdlc_flathashmap.h:472
value_type * pointer
Definition bdlc_flathashmap.h:471
bsl::ptrdiff_t difference_type
Definition bdlc_flathashmap.h:466
friend void swap(FlatHashMap< K, V, H, E > &, FlatHashMap< K, V, H, E > &)
bsl::pair< iterator, bool > insert_or_assign(BloombergLP::bslmf::MovableRef< KEY > key, M &&obj)
const value_type & const_reference
Definition bdlc_flathashmap.h:470
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, const_iterator >::type find(const LOOKUP_KEY &key) const
Definition bdlc_flathashmap.h:1292
void clear()
Definition bdlc_flathashmap.h:1746
VALUE & at(const KEY &key)
Definition bdlc_flathashmap.h:1731
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::pair< iterator, bool > >::type insert_or_assign(LOOKUP_KEY &&key, M &&obj)
Definition bdlc_flathashmap.h:962
EQUAL key_eq() const
Definition bdlc_flathashmap.h:2084
iterator find(const KEY &key)
Definition bdlc_flathashmap.h:1821
bool contains(const KEY &key) const
Definition bdlc_flathashmap.h:2040
ImplType::const_iterator const_iterator
Definition bdlc_flathashmap.h:474
bsl::enable_if< bsl::is_convertible< VALUE_TYPE, value_type >::value, iterator >::type insert(const_iterator, BSLS_COMPILERFEATURES_FORWARD_REF(VALUE_TYPE) value)
Definition bdlc_flathashmap.h:902
bsl::pair< iterator, bool > insert_or_assign(const KEY &key, M &&obj)
bool empty() const
Definition bdlc_flathashmap.h:2054
const_iterator cbegin() const
Definition bdlc_flathashmap.h:2122
bsl::size_t size() const
Return the number of elements in this map.
Definition bdlc_flathashmap.h:2105
bsl::enable_if< bsl::is_convertible< VALUE_TYPE, value_type >::value, bsl::pair< iterator, bool > >::type insert(BSLS_COMPILERFEATURES_FORWARD_REF(VALUE_TYPE) value)
Definition bdlc_flathashmap.h:875
void rehash(bsl::size_t minimumCapacity)
Definition bdlc_flathashmap.h:1906
bslma::Allocator * allocator() const
Return the allocator used by this flat hash map to supply memory.
Definition bdlc_flathashmap.h:2147
bsl::pair< iterator, bool > emplace(ARGS &&... args)
bsl::pair< iterator, iterator > equal_range(const KEY &key)
Definition bdlc_flathashmap.h:1754
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition bdlc_flathashmap.h:2153
const_iterator cend() const
Definition bdlc_flathashmap.h:2130
void reserve(bsl::size_t numEntries)
Definition bdlc_flathashmap.h:1913
float load_factor() const
Definition bdlc_flathashmap.h:2091
HASH hash_function() const
Definition bdlc_flathashmap.h:2077
~FlatHashMap()
Destroy this object and each of its elements.
Definition bdlc_flathashmap.h:1667
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::pair< const_iterator, const_iterator > >::type equal_range(const LOOKUP_KEY &key) const
Definition bdlc_flathashmap.h:1272
bsl::size_t erase(const KEY &key)
Definition bdlc_flathashmap.h:1782
iterator begin()
Definition bdlc_flathashmap.h:1992
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, VALUE & >::type at(const LOOKUP_KEY &key)
Definition bdlc_flathashmap.h:698
FlatHashMap & operator=(const FlatHashMap &rhs)
Definition bdlc_flathashmap.h:1675
EQUAL key_compare
Definition bdlc_flathashmap.h:467
KEY key_type
Definition bdlc_flathashmap.h:463
FlatHashMap()
Definition bdlc_flathashmap.h:1468
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::size_t >::type erase(LOOKUP_KEY &&key)
Definition bdlc_flathashmap.h:806
VALUE & operator[](const KEY &key)
Definition bdlc_flathashmap.h:1717
ImplType::iterator iterator
Definition bdlc_flathashmap.h:473
float max_load_factor() const
Definition bdlc_flathashmap.h:2098
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::size_t >::type count(const LOOKUP_KEY &key) const
Definition bdlc_flathashmap.h:1235
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, constVALUE & >::type at(const LOOKUP_KEY &key) const
Definition bdlc_flathashmap.h:1186
value_type & reference
Definition bdlc_flathashmap.h:469
void reset()
Definition bdlc_flathashmap.h:1920
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bool >::type contains(const LOOKUP_KEY &key) const
Definition bdlc_flathashmap.h:1213
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, iterator >::type find(const LOOKUP_KEY &key)
Definition bdlc_flathashmap.h:847
bsl::size_t capacity() const
Definition bdlc_flathashmap.h:2033
iterator emplace_hint(const_iterator hint, ARGS &&... args)
Definition bdlc_flathashmap.h:1773
bsl::size_t count(const KEY &key) const
Definition bdlc_flathashmap.h:2047
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, iterator >::type insert_or_assign(const_iterator, LOOKUP_KEY &&key, MAPPED &&obj)
Definition bdlc_flathashmap.h:1001
VALUE mapped_type
Definition bdlc_flathashmap.h:464
bsl::pair< typename bsl::add_const< KEY >::type, VALUE > value_type
Definition bdlc_flathashmap.h:461
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, bsl::pair< iterator, iterator > >::type equal_range(const LOOKUP_KEY &key)
Definition bdlc_flathashmap.h:741
iterator end()
Definition bdlc_flathashmap.h:2000
bsl::size_t size_type
Definition bdlc_flathashmap.h:465
Definition bdlc_flathashtable.h:326
void clear()
Definition bdlc_flathashtable.h:1875
bsl::size_t erase(const KEY &key)
Definition bdlc_flathashtable.h:1927
float max_load_factor() const
Definition bdlc_flathashtable.h:2404
const_iterator cbegin() const
Definition bdlc_flathashtable.h:2440
void swap(FlatHashTable &other)
Definition bdlc_flathashtable.h:2266
bsl::pair< iterator, bool > insert(const ENTRY &entry)
Definition bdlc_flathashtable.h:2050
void reset()
Definition bdlc_flathashtable.h:2154
bsl::pair< iterator, bool > emplace(ARGS &&... args)
iterator find(const KEY &key)
Definition bdlc_flathashtable.h:2036
iterator end()
Definition bdlc_flathashtable.h:2257
bool empty() const
Definition bdlc_flathashtable.h:2318
bsl::pair< iterator, bool > try_emplace(const KEY &key, ARGS &&... args)
bslma::Allocator * allocator() const
Return the allocator used by this hash table to supply memory.
Definition bdlc_flathashtable.h:2466
bsl::size_t capacity() const
Definition bdlc_flathashtable.h:2284
bslstl::ForwardIterator< const bsl::pair< KEY, VALUE >, IteratorImp > const_iterator
Definition bdlc_flathashtable.h:343
bslstl::ForwardIterator< bsl::pair< KEY, VALUE >, IteratorImp > iterator
Definition bdlc_flathashtable.h:341
EQUAL key_eq() const
Definition bdlc_flathashtable.h:2380
bool contains(const KEY &key) const
Definition bdlc_flathashtable.h:2291
iterator begin()
Definition bdlc_flathashtable.h:2240
void reserve(bsl::size_t numEntries)
Definition bdlc_flathashtable.h:2135
const_iterator cend() const
Definition bdlc_flathashtable.h:2448
bsl::size_t size() const
Return the number of entries in this table.
Definition bdlc_flathashtable.h:2412
bsl::size_t count(const KEY &key) const
Definition bdlc_flathashtable.h:2310
HASH hash_function() const
Definition bdlc_flathashtable.h:2373
float load_factor() const
Definition bdlc_flathashtable.h:2391
void rehash(bsl::size_t minimumCapacity)
Definition bdlc_flathashtable.h:2114
bsl::pair< iterator, iterator > equal_range(const KEY &key)
Definition bdlc_flathashtable.h:1894
Definition bslstl_pair.h:1280
static void swap(T *a, T *b)
Definition bslalg_swaputil.h:182
Definition bslh_fibonaccibadhashwrapper.h:165
Definition bslim_printer.h:604
void printValue(const TYPE &data) const
Definition bslim_printer.h:1240
void end(bool suppressBracket=false) const
void start(bool suppressBracket=false) const
Definition bslma_allocator.h:545
Definition bslma_destructorguard.h:132
Definition bslmf_movableref.h:752
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlc_bitarray.h:506
void swap(BitArray &a, BitArray &b)
bool operator==(const BitArray &lhs, const BitArray &rhs)
bool operator!=(const BitArray &lhs, const BitArray &rhs)
BitArray operator<<(const BitArray &array, bsl::size_t numBits)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
ALLOCATOR & lhs
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
Definition bdlc_flathashmap.h:2218
Definition baljsn_encoder_testtypes.h:76
Definition bdlbb_blob.h:579
Definition bdlc_flathashmap.h:394
static void constructFromKey(ENTRY *entry, bslma::Allocator *allocator, BSLS_COMPILERFEATURES_FORWARD_REF(KEY_TYPE) key)
Definition bdlc_flathashmap.h:1435
static const KEY & key(const ENTRY &entry)
Return the key of the specified entry.
Definition bdlc_flathashmap.h:1456
static void construct(ENTRY *entry, bslma::Allocator *allocator, ARGS &&... args)
Definition bdlc_flathashmap.h:1419
Definition bslmf_enableif.h:530
Definition bslstl_equalto.h:316
Definition bslalg_hasstliterators.h:99
static void construct(TARGET_TYPE *address, const ALLOCATOR &allocator)
Definition bslma_constructionutil.h:1244
Definition bslma_usesbslmaallocator.h:344
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1067
Definition bsls_objectbuffer.h:277
TYPE * address()
Definition bsls_objectbuffer.h:335
TYPE & object()
Definition bsls_objectbuffer.h:352