BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_set.h
Go to the documentation of this file.
1/// @file bslstl_set.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_set.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_SET
9#define INCLUDED_BSLSTL_SET
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_set bslstl_set
15/// @brief Provide an STL-compliant set class.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_set
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_set-purpose"> Purpose</a>
25/// * <a href="#bslstl_set-classes"> Classes </a>
26/// * <a href="#bslstl_set-description"> Description </a>
27/// * <a href="#bslstl_set-requirements-on-key"> Requirements on KEY </a>
28/// * <a href="#bslstl_set-glossary"> Glossary </a>
29/// * <a href="#bslstl_set-memory-allocation"> Memory Allocation </a>
30/// * <a href="#bslstl_set-bslma-style-allocators"> bslma-Style Allocators </a>
31/// * <a href="#bslstl_set-operations"> Operations </a>
32/// * <a href="#bslstl_set-usage"> Usage </a>
33/// * <a href="#bslstl_set-example-1-creating-a-holiday-calendar"> Example 1: Creating a Holiday Calendar </a>
34///
35/// # Purpose {#bslstl_set-purpose}
36/// Provide an STL-compliant set class.
37///
38/// # Classes {#bslstl_set-classes}
39///
40/// - bsl::set: STL-compatible set template
41///
42/// **Canonical header:** bsl_set.h
43///
44/// @see bslstl_multiset, bslstl_map
45///
46/// # Description {#bslstl_set-description}
47/// This component defines a single class template `bsl::set`,
48/// implementing the standard container holding an ordered sequence of unique
49/// keys.
50///
51/// An instantiation of `set` is an allocator-aware, value-semantic type whose
52/// salient attributes are its size (number of keys) and the ordered sequence of
53/// keys the `set` contains. If `set` is instantiated with a key type that is
54/// not itself value-semantic, then it will not retain all of its value-semantic
55/// qualities. In particular, if the key type cannot be tested for equality,
56/// then a set containing that type cannot be tested for equality. It is even
57/// possible to instantiate `set` with a key type that does not have a
58/// copy-constructor, in which case the `set` will not be copyable.
59///
60/// A set meets the requirements of an associative container with bidirectional
61/// iterators in the C++ standard [23.2.4]. The `set` implemented here adheres
62/// to the C++11 standard when compiled with a C++11 compiler, and makes the
63/// best approximation when compiled with a C++03 compiler. In particular, for
64/// C++03 we emulate move semantics, but limit forwarding (in `emplace`) to
65/// `const` lvalues, and make no effort to emulate `noexcept` or
66/// initializer-lists.
67///
68/// ## Requirements on KEY {#bslstl_set-requirements-on-key}
69///
70///
71/// A `set` is a fully "Value-Semantic Type" (see @ref bsldoc_glossary ) only if
72/// the supplied `KEY` template parameters is fully value-semantic. It is
73/// possible to instantiate a `set` with `KEY` parameter arguments that do not
74/// provide a full set of value-semantic operations, but then some methods of
75/// the container may not be instantiable. The following terminology, adopted
76/// from the C++11 standard, is used in the function documentation of `set` to
77/// describe a function's requirements for the `KEY` template parameter. These
78/// terms are also defined in section [17.6.3.1] of the C++11 standard. Note
79/// that, in the context of a `set` instantiation, the requirements apply
80/// specifically to the set's entry type, `value_type`, which is an alias for
81/// `KEY`.
82///
83/// ## Glossary {#bslstl_set-glossary}
84///
85///
86/// @code
87/// Legend
88/// ------
89/// 'X' - denotes an allocator-aware container type (e.g., 'set')
90/// 'T' - 'value_type' associated with 'X'
91/// 'A' - type of the allocator used by 'X'
92/// 'm' - lvalue of type 'A' (allocator)
93/// 'p', - address ('T *') of uninitialized storage for a 'T' within an 'X'
94/// 'rv' - rvalue of type (non-'const') 'T'
95/// 'v' - rvalue or lvalue of type (possibly 'const') 'T'
96/// 'args' - 0 or more arguments
97/// @endcode
98/// The following terms are used to more precisely specify the requirements on
99/// template parameter types in function-level documentation.
100///
101/// *default-insertable*: `T` has a default constructor. More precisely, `T`
102/// is `default-insertable` into `X` means that the following expression is
103/// well-formed:
104/// `allocator_traits<A>::construct(m, p)`
105///
106/// *move-insertable*: `T` provides a constructor that takes an rvalue of type
107/// (non-`const`) `T`. More precisely, `T` is `move-insertable` into `X`
108/// means that the following expression is well-formed:
109/// `allocator_traits<A>::construct(m, p, rv)`
110///
111/// *copy-insertable*: `T` provides a constructor that takes an lvalue or
112/// rvalue of type (possibly `const`) `T`. More precisely, `T` is
113/// `copy-insertable` into `X` means that the following expression is
114/// well-formed:
115/// `allocator_traits<A>::construct(m, p, v)`
116///
117/// *move-assignable*: `T` provides an assignment operator that takes an rvalue
118/// of type (non-`const`) `T`.
119///
120/// *copy-assignable*: `T` provides an assignment operator that takes an lvalue
121/// or rvalue of type (possibly `const`) `T`.
122///
123/// *emplace-constructible*: `T` is `emplace-constructible` into `X` from
124/// `args` means that the following expression is well-formed:
125/// `allocator_traits<A>::construct(m, p, args)`
126///
127/// *erasable*: `T` provides a destructor. More precisely, `T` is `erasable`
128/// from `X` means that the following expression is well-formed:
129/// `allocator_traits<A>::destroy(m, p)`
130///
131/// *equality-comparable*: The type provides an equality-comparison operator
132/// that defines an equivalence relationship and is both reflexive and
133/// transitive.
134///
135/// ## Memory Allocation {#bslstl_set-memory-allocation}
136///
137///
138/// The type supplied as a set's `ALLOCATOR` template parameter determines how
139/// that set will allocate memory. The `set` template supports allocators
140/// meeting the requirements of the C++11 standard [17.6.3.5], in addition it
141/// supports scoped-allocators derived from the `bslma::Allocator` memory
142/// allocation protocol. Clients intending to use `bslma` style allocators
143/// should use the template's default `ALLOCATOR` type: The default type for
144/// the `ALLOCATOR` template parameter, `bsl::allocator`, provides a C++11
145/// standard-compatible adapter for a `bslma::Allocator` object.
146///
147/// ### bslma-Style Allocators {#bslstl_set-bslma-style-allocators}
148///
149///
150/// If the (template parameter) type `ALLOCATOR` of a `set` instantiation' is
151/// `bsl::allocator`, then objects of that set type will conform to the standard
152/// behavior of a `bslma`-allocator-enabled type. Such a set accepts an
153/// optional `bslma::Allocator` argument at construction. If the address of a
154/// `bslma::Allocator` object is explicitly supplied at construction, it is used
155/// to supply memory for the set throughout its lifetime; otherwise, the set
156/// will use the default allocator installed at the time of the set's
157/// construction (see @ref bslma_default ). In addition to directly allocating
158/// memory from the indicated `bslma::Allocator`, a set supplies that
159/// allocator's address to the constructors of contained objects of the
160/// (template parameter) type `KEY` with the `bslma::UsesBslmaAllocator` trait.
161///
162/// ## Operations {#bslstl_set-operations}
163///
164///
165/// This section describes the run-time complexity of operations on instances
166/// of `set`:
167/// @code
168/// Legend
169/// ------
170/// 'K' - (template parameter) type 'KEY' of the set
171/// 'a', 'b' - two distinct objects of type 'set<K>'
172/// 'rv' - modifiable rvalue of type 'set<K>'
173/// 'n', 'm' - number of elements in 'a' and 'b' respectively
174/// 'c' - comparator providing an ordering for objects of type 'K'
175/// 'al - an STL-style memory allocator
176/// 'i1', 'i2' - two iterators defining a sequence of 'value_type' objects
177/// 'k' - an object of type 'K'
178/// 'rk' - modifiable rvalue of type 'K'
179/// 'p1', 'p2' - two 'const' iterators belonging to 'a'
180/// distance(i1,i2) - the number of elements in the range [i1, i2)
181///
182/// +----------------------------------------------------+--------------------+
183/// | Operation | Complexity |
184/// +====================================================+====================+
185/// | set<K> a; (default construction) | O[1] |
186/// | set<K> a(al); | |
187/// | set<K> a(c, al); | |
188/// +----------------------------------------------------+--------------------+
189/// | set<K> a(rv); (move construction) | O[1] if 'a' and |
190/// | set<K> a(rv, al); | 'rv' use the same |
191/// | | allocator, |
192/// | | O[n] otherwise |
193/// +----------------------------------------------------+--------------------+
194/// | set<K> a(b); (copy construction) | O[n] |
195/// | set<K> a(b, al); | |
196/// +----------------------------------------------------+--------------------+
197/// | set<K> a(i1, i2); | O[N] if [i1, i2) |
198/// | set<K> a(i1, i2, al); | is sorted with |
199/// | set<K> a(i1, i2, c, al); | 'a.value_comp()', |
200/// | | O[N * log(N)] |
201/// | | otherwise, where N |
202/// | | is distance(i1,i2) |
203/// +----------------------------------------------------+--------------------+
204/// | a.~set<K>(); (destruction) | O[n] |
205/// +----------------------------------------------------+--------------------+
206/// | a = rv; (move assignment) | O[1] if 'a' and |
207/// | | 'rv' use the same |
208/// | | allocator, |
209/// | | O[n] otherwise |
210/// +----------------------------------------------------+--------------------+
211/// | a = b; (copy assignment) | O[n] |
212/// +----------------------------------------------------+--------------------+
213/// | a.begin(), a.end(), a.cbegin(), a.cend(), | O[1] |
214/// | a.rbegin(), a.rend(), a.crbegin(), a.crend() | |
215/// +----------------------------------------------------+--------------------+
216/// | a == b, a != b | O[n] |
217/// +----------------------------------------------------+--------------------+
218/// | a < b, a <= b, a > b, a >= b | O[n] |
219/// +----------------------------------------------------+--------------------+
220/// | a.swap(b), swap(a, b) | O[1] if 'a' and |
221/// | | 'b' use the same |
222/// | | allocator, |
223/// | | O[n + m] otherwise |
224/// +----------------------------------------------------+--------------------+
225/// | a.size() | O[1] |
226/// +----------------------------------------------------+--------------------+
227/// | a.max_size() | O[1] |
228/// +----------------------------------------------------+--------------------+
229/// | a.empty() | O[1] |
230/// +----------------------------------------------------+--------------------+
231/// | get_allocator() | O[1] |
232/// +----------------------------------------------------+--------------------+
233/// | a.insert(k) | O[log(n)] |
234/// | a.insert(rk) | |
235/// | a.emplace(Args&&...) | |
236/// +----------------------------------------------------+--------------------+
237/// | a.insert(p1, k) | amortized constant |
238/// | a.insert(p1, rk) | if the value is |
239/// | a.emplace(p1, Args&&...) | inserted right |
240/// | | before p1, |
241/// | | O[log(n)] |
242/// | | otherwise |
243/// +----------------------------------------------------+--------------------+
244/// | a.insert(i1, i2) | O[log(N) * |
245/// | | distance(i1,i2)] |
246/// | | |
247/// | | where N is |
248/// | | n + distance(i1,i2)|
249/// +----------------------------------------------------+--------------------+
250/// | a.erase(p1) | amortized constant |
251/// +----------------------------------------------------+--------------------+
252/// | a.erase(k) | O[log(n) + |
253/// | | a.count(k)] |
254/// +----------------------------------------------------+--------------------+
255/// | a.erase(p1, p2) | O[log(n) + |
256/// | | distance(p1, p2)] |
257/// +----------------------------------------------------+--------------------+
258/// | a.erase(p1, p2) | O[log(n) + |
259/// | | distance(p1, p2)] |
260/// +----------------------------------------------------+--------------------+
261/// | a.clear() | O[n] |
262/// +----------------------------------------------------+--------------------+
263/// | a.key_comp() | O[1] |
264/// +----------------------------------------------------+--------------------+
265/// | a.value_comp() | O[1] |
266/// +----------------------------------------------------+--------------------+
267/// | a.contains(k) | O[log(n)] |
268/// +----------------------------------------------------+--------------------+
269/// | a.find(k) | O[log(n)] |
270/// +----------------------------------------------------+--------------------+
271/// | a.count(k) | O[log(n) + |
272/// | | a.count(k)] |
273/// +----------------------------------------------------+--------------------+
274/// | a.lower_bound(k) | O[log(n)] |
275/// +----------------------------------------------------+--------------------+
276/// | a.upper_bound(k) | O[log(n)] |
277/// +----------------------------------------------------+--------------------+
278/// | a.equal_range(k) | O[log(n)] |
279/// +----------------------------------------------------+--------------------+
280/// @endcode
281///
282/// ## Usage {#bslstl_set-usage}
283///
284///
285/// In this section we show intended use of this component.
286///
287/// ### Example 1: Creating a Holiday Calendar {#bslstl_set-example-1-creating-a-holiday-calendar}
288///
289///
290/// In this example, we will utilize `bsl::set` to define and implement a class,
291/// `HolidayCalendar`, that provides a calendar that allows client to add and
292/// remove holiday dates and determine whether a particular date is a holiday.
293///
294/// First, we define and implement the methods of a value-semantic type,
295/// `MyDate`, that represents a date: (Note that for brevity, we do not
296/// explicitly document the invariants of a valid date.)
297/// @code
298/// /// This class implements a value-semantic attribute class
299/// /// characterizing a date according to the (Gregorian) Unix date
300/// /// convention.
301/// class MyDate {
302///
303/// // DATA
304/// int d_year;
305/// int d_month;
306/// int d_day;
307///
308/// public:
309/// // CREATORS
310///
311/// /// Create a `MyDate` object having the value represented by the
312/// /// specified `year`, `month`, and `day`. The behavior is undefined
313/// /// unless the value represented by `year`, `month`, and `day` is
314/// /// valid.
315/// MyDate(int year, int month, int day)
316/// : d_year(year), d_month(month), d_day(day)
317/// {
318/// }
319///
320/// /// Create a `MyDate` object having the same value as the specified
321/// /// `original` object.
322/// MyDate(const MyDate& original)
323/// : d_year(original.d_year)
324/// , d_month(original.d_month)
325/// , d_day(original.d_day)
326/// {
327/// }
328///
329/// /// Destroy this object
330/// //! ~MyDate() = default;
331///
332/// // MANIPULATORS
333///
334/// /// Assign to this object the value of the specified `rhs` object,
335/// /// and return a reference providing modifiable access to this
336/// /// object.
337/// MyDate& operator=(const MyDate& rhs)
338/// {
339/// d_year = rhs.d_year;
340/// d_month = rhs.d_month;
341/// d_day = rhs.d_day;
342/// return *this;
343/// }
344///
345/// // ACCESSORS
346///
347/// /// Return the year of this date.
348/// int year() const
349/// {
350/// return d_year;
351/// }
352///
353/// /// Return the month of this date.
354/// int month() const
355/// {
356/// return d_month;
357/// }
358///
359/// /// Return the day of this date.
360/// int day() const
361/// {
362/// return d_day;
363/// }
364///
365/// };
366///
367/// // FREE FUNCTIONS
368///
369/// /// Return `true` if the specified `lhs` and `rhs` objects have the same
370/// /// value, and `false` otherwise. Two `MyDate` objects have the same
371/// /// value if each of their corresponding `year`, `month`, and `day`
372/// /// attributes respective have the same value.
373/// inline
374/// bool operator==(const MyDate& lhs, const MyDate& rhs)
375/// {
376/// return lhs.year() == rhs.year() &&
377/// lhs.month() == rhs.month() &&
378/// lhs.day() == rhs.day();
379/// }
380///
381/// /// Return `true` if the specified `lhs` and `rhs` objects do not have
382/// /// the same value, and `false` otherwise. Two `MyDate` objects do not
383/// /// have the same value if each of their corresponding `year`, `month`,
384/// /// and `day` attributes respective do not have the same value.
385/// inline
386/// bool operator!=(const MyDate& lhs, const MyDate& rhs)
387/// {
388/// return !(lhs == rhs);
389/// }
390/// @endcode
391/// Then, we define a comparison functor for `MyDate` objects in order for them
392/// to be stored in a `bsl::set` object:
393/// @code
394/// /// This `struct` defines an ordering on `MyDate` objects, allowing them
395/// /// to be included in associative containers such as `bsl::set`.
396/// struct MyDateLess {
397///
398/// /// Return `true` if the value of the specified `lhs` is less than
399/// /// (ordered before) the value of the specified `rhs`, and `false`
400/// /// otherwise. The `lhs` value is considered less than the `rhs`
401/// /// value if the date represented by `lhs` is earlier than the date
402/// /// represented by `rhs` in time.
403/// bool operator() (const MyDate& lhs, const MyDate& rhs) const
404/// {
405/// if (lhs.year() < rhs.year()) return true;
406/// if (lhs.year() == rhs.year()) {
407/// if (lhs.month() < rhs.month()) return true;
408/// if (lhs.month() == rhs.month()) {
409/// if (lhs.day() < rhs.day()) return true;
410/// }
411/// }
412/// return false;
413/// }
414/// };
415/// @endcode
416/// Next, we define `HolidayCalendar`:
417/// @code
418/// /// This class provides a value-semantic type that allows clients to
419/// /// modify and query a set of dates considered to be holidays.
420/// class HolidayCalendar {
421/// @endcode
422/// Here, we create a type alias, `DateSet`, for a `bsl::set` that will serve as
423/// the data member for a `HolidayCalendar`. A `DateSet` has keys of type
424/// `MyDate`, and a comparator of type `MyDateLess`. We use the default
425/// `ALLOCATOR` template parameter as we intend to use `HolidayCalendar` with
426/// `bslma` style allocators:
427/// @code
428/// // PRIVATE TYPES
429///
430/// /// This `typedef` is an alias for a set of `MyDate` objects.
431/// typedef bsl::set<MyDate, MyDateLess> DateSet;
432///
433/// // DATA
434/// DateSet d_holidayDates; // set of dates considered to be holidays
435///
436/// public:
437/// // PUBLIC TYPES
438///
439/// /// This `typedef` provides an alias for the type of an iterator
440/// /// providing non-modifiable access to holiday dates in a
441/// /// `HolidayCalendar`.
442/// typedef DateSet::const_iterator ConstIterator;
443///
444/// // CREATORS
445///
446/// /// Create an empty `HolidayCalendar` object. Optionally specify a
447/// /// `basicAllocator` used to supply memory. If `basicAllocator` is
448/// /// 0, the currently installed default allocator is used.
449/// HolidayCalendar(bslma::Allocator *basicAllocator = 0);
450///
451/// /// Create a `HolidayCalendar` object having the same value as the
452/// /// specified `original` object. Optionally specify a
453/// /// `basicAllocator` used to supply memory. If `basicAllocator` is
454/// /// 0, the currently installed default allocator is used.
455/// HolidayCalendar(const HolidayCalendar& original,
456/// bslma::Allocator *basicAllocator = 0);
457///
458/// /// Destroy this object.
459/// //! ~HolidayCalendar() = default;
460///
461/// // MANIPULATORS
462///
463/// /// Add the specified `date` as a holiday date maintained by this
464/// /// calendar. If `date` is already a holiday date, this method has
465/// /// no effect.
466/// void addHolidayDate(const MyDate& date);
467///
468/// /// Remove the specify `date` from the set of holiday dates
469/// /// maintained by this calendar. If `date` is not a holiday date,
470/// /// this method has no effect.
471/// void removeHolidayDate(const MyDate& date);
472///
473/// // ACCESSORS
474///
475/// /// Return `true` if the specified `date` is in the set of holiday
476/// /// dates maintained by this calendar, and return `false` otherwise.
477/// bool isHolidayDate(const MyDate& date) const;
478///
479/// /// Return an iterator providing non-modifiable access to the first
480/// /// date in the ordered sequence of holiday dates maintained by this
481/// /// calendar.
482/// ConstIterator beginHolidayDates() const;
483///
484/// /// Return an iterator providing non-modifiable access to
485/// /// past-the-end date in the ordered sequence of holiday dates
486/// /// maintained by this calendar.
487/// ConstIterator endHolidayDates() const;
488/// };
489/// @endcode
490/// Then, we declare the free operators for `HolidayCalendar`:
491/// @code
492/// /// Return `true` if the specified `lhs` and `rhs` objects have the same
493/// /// value, and `false` otherwise. Two `HolidayCalendar` objects have
494/// /// the same value if they have the same number of holiday dates, and
495/// /// each corresponding holiday date, in their respective ordered
496/// /// sequence of dates, is the same.
497/// inline
498/// bool operator==(const HolidayCalendar& lhs, const HolidayCalendar& rhs);
499///
500/// /// Return `true` if the specified `lhs` and `rhs` objects do not have
501/// /// the same value, and `false` otherwise. Two `HolidayCalendar`
502/// /// objects do not have the same value if they either differ in their
503/// /// number of holiday dates, or if any of the corresponding holiday
504/// /// dates, in their respective ordered sequences of dates, is not the
505/// /// same.
506/// inline
507/// bool operator!=(const HolidayCalendar& lhs, const HolidayCalendar& rhs);
508/// @endcode
509/// Now, we define the implementations methods of the `HolidayCalendar` class:
510/// @code
511/// // CREATORS
512/// HolidayCalendar::HolidayCalendar(bslma::Allocator *basicAllocator)
513/// : d_holidayDates(basicAllocator)
514/// {
515/// }
516/// @endcode
517/// Notice that, on construction, we pass the `bsl::set` object the specified
518/// `bsl::Allocator` object.
519/// @code
520/// // MANIPULATORS
521/// void HolidayCalendar::addHolidayDate(const MyDate& date)
522/// {
523/// d_holidayDates.insert(date);
524/// }
525///
526/// void HolidayCalendar::removeHolidayDate(const MyDate& date)
527/// {
528/// d_holidayDates.erase(date);
529/// }
530///
531/// // ACCESSORS
532/// bool HolidayCalendar::isHolidayDate(const MyDate& date) const
533/// {
534/// return d_holidayDates.find(date) != d_holidayDates.end();
535/// }
536///
537/// HolidayCalendar::ConstIterator HolidayCalendar::beginHolidayDates() const
538/// {
539/// return d_holidayDates.begin();
540/// }
541///
542/// HolidayCalendar::ConstIterator HolidayCalendar::endHolidayDates() const
543/// {
544/// return d_holidayDates.end();
545/// }
546/// @endcode
547/// Finally, we implement the free operators for `HolidayCalendar`:
548/// @code
549/// inline
550/// bool operator==(const HolidayCalendar& lhs, const HolidayCalendar& rhs)
551/// {
552/// return lhs.d_holidayDates == rhs.d_holidayDates;
553/// }
554///
555/// inline
556/// bool operator!=(const HolidayCalendar& lhs, const HolidayCalendar& rhs)
557/// {
558/// return !(lhs == rhs);
559/// }
560/// @endcode
561/// @}
562/** @} */
563/** @} */
564
565/** @addtogroup bsl
566 * @{
567 */
568/** @addtogroup bslstl
569 * @{
570 */
571/** @addtogroup bslstl_set
572 * @{
573 */
574
575#include <bslscm_version.h>
576
577#include <bslstl_algorithm.h>
578#include <bslstl_iterator.h>
579#include <bslstl_iteratorutil.h>
580#include <bslstl_pair.h>
581#include <bslstl_setcomparator.h>
582#include <bslstl_stdexceptutil.h>
583#include <bslstl_treeiterator.h>
584#include <bslstl_treenode.h>
585#include <bslstl_treenodepool.h>
586
587#include <bslalg_rangecompare.h>
588#include <bslalg_rbtreeanchor.h>
589#include <bslalg_rbtreenode.h>
590#include <bslalg_rbtreeutil.h>
591#include <bslalg_swaputil.h>
594
595#include <bslma_isstdallocator.h>
596#include <bslma_bslallocator.h>
598
599#include <bslmf_isconvertible.h>
602#include <bslmf_movableref.h>
603#include <bslmf_typeidentity.h>
604#include <bslmf_util.h> // 'forward(V)'
605
606#include <bsls_assert.h>
608#include <bsls_keyword.h>
609#include <bsls_performancehint.h>
610#include <bsls_util.h> // 'forward<T>(V)'
611
612#include <functional>
613
614#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
615# include <initializer_list>
616#endif
617
618#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
619#include <bsls_nativestd.h>
620#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
621
622#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
623#include <type_traits> // 'std::is_nothrow_move_assignable'
624#endif
625
626#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
627// Include version that can be compiled with C++03
628// Generated on Thu Oct 21 10:11:37 2021
629// Command line: sim_cpp11_features.pl bslstl_set.h
630# define COMPILING_BSLSTL_SET_H
631# include <bslstl_set_cpp03.h>
632# undef COMPILING_BSLSTL_SET_H
633#else
634
635namespace bsl {
636
637 // =========
638 // class set
639 // =========
640
641/// This class template implements a value-semantic container type holding
642/// an ordered sequence of unique keys (of the template parameter type,
643/// `KEY`).
644///
645/// This class:
646/// * supports a complete set of *value-semantic* operations
647/// except for `BDEX` serialization
648/// * is *exception-neutral* (agnostic except for the `at` method)
649/// * is *alias-safe*
650/// * is `const` *thread-safe*
651/// For terminology see @ref bsldoc_glossary .
652///
653/// See @ref bslstl_set
654template <class KEY,
655 class COMPARATOR = std::less<KEY>,
656 class ALLOCATOR = allocator<KEY> >
657class set {
658
659 // PRIVATE TYPES
660
661 /// This typedef is an alias for the type of key objects maintained by
662 /// this set.
663 typedef const KEY ValueType;
664
665 /// This typedef is an alias for the comparator used internally by this
666 /// set.
667 typedef BloombergLP::bslstl::SetComparator<KEY, COMPARATOR> Comparator;
668
669 /// This typedef is an alias for the type of nodes held by the tree (of
670 /// nodes) used to implement this set.
671 typedef BloombergLP::bslstl::TreeNode<KEY> Node;
672
673 /// This typedef is an alias for the factory type used to create and
674 /// destroy `Node` objects.
675 typedef BloombergLP::bslstl::TreeNodePool<KEY, ALLOCATOR> NodeFactory;
676
677 /// This typedef is an alias for the allocator traits type associated
678 /// with this container.
680
681 /// This typedef is a convenient alias for the utility associated with
682 /// movable references.
683 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
684
685 /// This class is a wrapper around the comparator and allocator data
686 /// members. It takes advantage of the empty-base optimization (EBO) so
687 /// that if the comparator is stateless, it takes up no space.
688 ///
689 /// TBD: This struct should eventually be replaced by the use of a
690 /// general EBO-enabled component that provides a `pair`-like interface
691 /// or a `tuple`.
692 ///
693 /// See @ref bslstl_set
694 class DataWrapper : public Comparator {
695
696 // DATA
697 NodeFactory d_pool; // pool of 'Node' objects
698
699 private:
700 // NOT IMPLEMENTED
701 DataWrapper(const DataWrapper&);
702 DataWrapper& operator=(const DataWrapper&);
703
704 public:
705 // CREATORS
706
707 /// Create a data wrapper using a copy of the specified `comparator`
708 /// to order keys and a copy of the specified `basicAllocator` to
709 /// supply memory.
710 explicit DataWrapper(const COMPARATOR& comparator,
711 const ALLOCATOR& basicAllocator);
712
713 /// Create a data wrapper initialized to the contents of the `pool`
714 /// associated with the specified `original` data wrapper. The
715 /// comparator and allocator associated with `original` are
716 /// propagated to the new data wrapper. `original` is left in a
717 /// valid but unspecified state.
718 DataWrapper(
719 BloombergLP::bslmf::MovableRef<DataWrapper> original);// IMPLICIT
720
721 // MANIPULATORS
722
723 /// Return a reference providing modifiable access to the node
724 /// factory associated with this data wrapper.
725 NodeFactory& nodeFactory();
726
727 // ACCESSORS
728
729 /// Return a reference providing non-modifiable access to the node
730 /// factory associated with this data wrapper.
731 const NodeFactory& nodeFactory() const;
732 };
733
734 // DATA
735 DataWrapper d_compAndAlloc;
736 // comparator and pool of `Node`
737 // objects
738
739 BloombergLP::bslalg::RbTreeAnchor d_tree; // balanced tree of `Node`
740 // objects
741
742 public:
743 // PUBLIC TYPES
744 typedef KEY key_type;
745 typedef KEY value_type;
746 typedef COMPARATOR key_compare;
747 typedef COMPARATOR value_compare;
748 typedef ALLOCATOR allocator_type;
751
756
757 typedef BloombergLP::bslstl::TreeIterator<const value_type,
758 Node,
760 typedef BloombergLP::bslstl::TreeIterator<const value_type,
761 Node,
763 typedef bsl::reverse_iterator<iterator> reverse_iterator;
764 typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
765
766 private:
767 // PRIVATE MANIPULATORS
768
769 /// Return a reference providing modifiable access to the node-allocator
770 /// for this tree.
771 NodeFactory& nodeFactory();
772
773 /// Return a reference providing modifiable access to the comparator for
774 /// this tree.
775 Comparator& comparator();
776
777 /// Efficiently exchange the value, comparator, and allocator of this
778 /// object with the value, comparator, and allocator of the specified
779 /// `other` object. This method provides the no-throw exception-safety
780 /// guarantee, *unless* swapping the (user-supplied) comparator or
781 /// allocator objects can throw.
782 void quickSwapExchangeAllocators(set& other);
783
784 /// Efficiently exchange the value and comparator of this object with
785 /// the value and comparator of the specified `other` object. This
786 /// method provides the no-throw exception-safety guarantee, *unless*
787 /// swapping the (user-supplied) comparator objects can throw. The
788 /// behavior is undefined unless this object was created with the same
789 /// allocator as `other`.
790 void quickSwapRetainAllocators(set& other);
791
792 // PRIVATE ACCESSORS
793
794 /// Return a reference providing non-modifiable access to the
795 /// node-allocator for this tree.
796 const NodeFactory& nodeFactory() const;
797
798 /// Return a reference providing non-modifiable access to the comparator
799 /// for this tree.
800 const Comparator& comparator() const;
801
802 public:
803 // CREATORS
804
806 /// Create an empty set. Optionally specify a `comparator` used to
807 /// order keys contained in this object. If `comparator` is not
808 /// supplied, a default-constructed object of the (template parameter)
809 /// type `COMPARATOR` is used. Optionally specify a `basicAllocator`
810 /// used to supply memory. If `basicAllocator` is not supplied, a
811 /// default-constructed object of the (template parameter) type
812 /// `ALLOCATOR` is used. If the type `ALLOCATOR` is `bsl::allocator`
813 /// and `basicAllocator` is not supplied, the currently installed
814 /// default allocator is used. Note that a `bslma::Allocator *` can be
815 /// supplied for `basicAllocator` if the type `ALLOCATOR` is
816 /// `bsl::allocator` (the default).
817 explicit set(const COMPARATOR& comparator,
818 const ALLOCATOR& basicAllocator = ALLOCATOR())
819 : d_compAndAlloc(comparator, basicAllocator),
820 d_tree()
821 {
822 // The implementation is placed here in the class definition to work
823 // around an AIX compiler bug, where the constructor can fail to
824 // compile because it is unable to find the definition of the default
825 // argument. This occurs when a templatized class wraps around the
826 // container and the comparator is defined after the new class.
827 }
828
829 /// Create an empty set that uses the specified `basicAllocator` to
830 /// supply memory. Use a default-constructed object of the (template
831 /// parameter) type `COMPARATOR` to order the keys contained in this
832 /// set. Note that a `bslma::Allocator *` can be supplied for
833 /// `basicAllocator` if the (template parameter) type `ALLOCATOR` is
834 /// `bsl::allocator` (the default).
835 explicit set(const ALLOCATOR& basicAllocator);
836
837 /// Create a set having the same value as the specified `original`
838 /// object. Use a copy of `original.key_comp()` to order the keys
839 /// contained in this set. Use the allocator returned by
840 /// `bsl::allocator_traits<ALLOCATOR>::
841 /// select_on_container_copy_construction(original.get_allocator())` to
842 /// allocate memory. This method requires that the (template parameter)
843 /// type `KEY` be `copy-insertable` into this set (see {Requirements on
844 /// `KEY`}).
845 set(const set& original);
846
847 /// Create a set having the same value as the specified `original`
848 /// object by moving (in constant time) the contents of `original` to
849 /// the new set. Use a copy of `original.key_comp()` to order the keys
850 /// contained in this set. The allocator associated with `original` is
851 /// propagated for use in the newly-created set. `original` is left in
852 /// a valid but unspecified state.
853 set(BloombergLP::bslmf::MovableRef<set> original); // IMPLICIT
854
855 /// Create a set having the same value as the specified `original`
856 /// object that uses the specified `basicAllocator` to supply memory.
857 /// Use a copy of `original.key_comp()` to order the keys contained in
858 /// this set. This method requires that the (template parameter) type
859 /// `KEY` be `copy-insertable` into this set (see {Requirements on
860 /// `KEY`}). Note that a `bslma::Allocator *` can be supplied for
861 /// `basicAllocator` if the (template parameter) type `ALLOCATOR` is
862 /// `bsl::allocator` (the default).
863 set(const set& original,
864 const typename type_identity<ALLOCATOR>::type& basicAllocator);
865
866 /// Create a set having the same value as the specified `original`
867 /// object that uses the specified `basicAllocator` to supply memory.
868 /// The contents of `original` are moved (in constant time) to the new
869 /// set if `basicAllocator == original.get_allocator()`, and are move-
870 /// inserted (in linear time) using `basicAllocator` otherwise.
871 /// `original` is left in a valid but unspecified state. Use a copy of
872 /// `original.key_comp()` to order the keys contained in this set. This
873 /// method requires that the (template parameter) type `KEY` be
874 /// `move-insertable` into this set (see {Requirements on `KEY`}). Note
875 /// that a `bslma::Allocator *` can be supplied for `basicAllocator` if
876 /// the (template parameter) type `ALLOCATOR` is `bsl::allocator` (the
877 /// default).
878 set(BloombergLP::bslmf::MovableRef<set> original,
879 const typename type_identity<ALLOCATOR>::type& basicAllocator);
880
881 /// Create a set, and insert each `value_type` object in the sequence
882 /// starting at the specified `first` element, and ending immediately
883 /// before the specified `last` element, ignoring those keys having a
884 /// value equivalent to that which appears earlier in the sequence.
885 /// Optionally specify a `comparator` used to order keys contained in
886 /// this object. If `comparator` is not supplied, a default-constructed
887 /// object of the (template parameter) type `COMPARATOR` is used.
888 /// Optionally specify a `basicAllocator` used to supply memory. If
889 /// `basicAllocator` is not supplied, a default-constructed object of
890 /// the (template parameter) type `ALLOCATOR` is used. If the type
891 /// `ALLOCATOR` is `bsl::allocator` and `basicAllocator` is not
892 /// supplied, the currently installed default allocator is used. If the
893 /// sequence `first` to `last` is ordered according to `comparator`,
894 /// then this operation has `O[N]` complexity, where `N` is the number
895 /// of elements between `first` and `last`, otherwise this operation has
896 /// `O[N * log(N)]` complexity. The (template parameter) type
897 /// `INPUT_ITERATOR` shall meet the requirements of an input iterator
898 /// defined in the C++11 standard [24.2.3] providing access to values of
899 /// a type convertible to `value_type`, and `value_type` must be
900 /// `emplace-constructible` from `*i` into this set, where `i` is a
901 /// dereferenceable iterator in the range `[first .. last)` (see
902 /// {Requirements on `KEY`}). The behavior is undefined unless `first`
903 /// and `last` refer to a sequence of valid values where `first` is at a
904 /// position at or before `last`. Note that a `bslma::Allocator *` can
905 /// be supplied for `basicAllocator` if the type `ALLOCATOR` is
906 /// `bsl::allocator` (the default).
907 template <class INPUT_ITERATOR>
908 set(INPUT_ITERATOR first,
909 INPUT_ITERATOR last,
910 const COMPARATOR& comparator = COMPARATOR(),
911 const ALLOCATOR& basicAllocator = ALLOCATOR());
912 template <class INPUT_ITERATOR>
913 set(INPUT_ITERATOR first,
914 INPUT_ITERATOR last,
915 const ALLOCATOR& basicAllocator);
916
917#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
918 set(std::initializer_list<KEY> values,
919 const COMPARATOR& comparator = COMPARATOR(),
920 const ALLOCATOR& basicAllocator = ALLOCATOR());
921 /// Create a set and insert each `value_type` object in the specified
922 /// `values` initializer list, ignoring those keys having a value
923 /// equivalent to that which appears earlier in the list. Optionally
924 /// specify a `comparator` used to order keys contained in this object.
925 /// If `comparator` is not supplied, a default-constructed object of the
926 /// (template parameter) type `COMPARATOR` is used. Optionally specify
927 /// a `basicAllocator` used to supply memory. If `basicAllocator` is
928 /// not supplied, a default-constructed object of the (template
929 /// parameter) type `ALLOCATOR` is used. If the type `ALLOCATOR` is
930 /// `bsl::allocator` and `basicAllocator` is not supplied, the currently
931 /// installed default allocator is used. If `values` is ordered
932 /// according to `comparator`, then this operation has `O[N]`
933 /// complexity, where `N` is the number of elements in `list`; otherwise
934 /// this operation has `O[N * log(N)]` complexity. This method requires
935 /// that the (template parameter) type `KEY` be `copy-insertable` into
936 /// this set (see {Requirements on `KEY`}). Note that a
937 /// `bslma::Allocator *` can be supplied for `basicAllocator` if the
938 /// type `ALLOCATOR` is `bsl::allocator` (the default).
939 set(std::initializer_list<KEY> values,
940 const ALLOCATOR& basicAllocator);
941#endif
942
943 /// Destroy this object.
945
946 // MANIPULATORS
947
948 /// Assign to this object the value and comparator of the specified
949 /// `rhs` object, propagate to this object the allocator of `rhs` if the
950 /// `ALLOCATOR` type has trait `propagate_on_container_copy_assignment`,
951 /// and return a reference providing modifiable access to this object.
952 /// If an exception is thrown, `*this` is left in a valid but
953 /// unspecified state. This method requires that the (template
954 /// parameter) type `KEY` be `copy-assignable` and `copy-insertable`
955 /// into this set (see {Requirements on `KEY`}).
956 set& operator=(const set& rhs);
957
958 /// Assign to this object the value and comparator of the specified
959 /// `rhs` object, propagate to this object the allocator of `rhs` if the
960 /// `ALLOCATOR` type has trait `propagate_on_container_move_assignment`,
961 /// and return a reference providing modifiable access to this object.
962 /// The contents of `rhs` are moved (in constant time) to this set if
963 /// `get_allocator() == rhs.get_allocator()` (after accounting for the
964 /// aforementioned trait); otherwise, all elements in this set are
965 /// either destroyed or move-assigned to and each additional element in
966 /// `rhs` is move-inserted into this set. `rhs` is left in a valid but
967 /// unspecified state, and if an exception is thrown, `*this` is left
968 /// in a valid but unspecified state. This method requires that the
969 /// (template parameter) type `KEY` be `move-assignable` and
970 /// `move-insertable` into this set (see {Requirements on `KEY`}).
971 set& operator=(BloombergLP::bslmf::MovableRef<set> rhs)
973 AllocatorTraits::is_always_equal::value
974 && std::is_nothrow_move_assignable<COMPARATOR>::value);
975
976#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
977 /// Assign to this object the value resulting from first clearing this
978 /// set and then inserting each `value_type` object in the specified
979 /// `values` initializer list, ignoring those keys having a value
980 /// equivalent to that which appears earlier in the list; return a
981 /// reference providing modifiable access to this object. This method
982 /// requires that the (template parameter) type `KEY` be
983 /// `copy-insertable` into this set (see {Requirements on `KEY`}).
984 set& operator=(std::initializer_list<KEY> values);
985#endif
986
987 /// Return an iterator providing modifiable access to the first
988 /// `value_type` object in the ordered sequence of `value_type` objects
989 /// maintained by this set, or the `end` iterator if this set is empty.
991
992 /// Return an iterator providing modifiable access to the past-the-end
993 /// element in the ordered sequence of `value_type` objects maintained
994 /// by this set.
996
997 /// Return a reverse iterator providing modifiable access to the last
998 /// `value_type` object in the ordered sequence of `value_type` objects
999 /// maintained by this set, or `rend` if this object is empty.
1001
1002 /// Return a reverse iterator providing modifiable access to the
1003 /// prior-to-the-beginning element in the ordered sequence of
1004 /// `value_type` objects maintained by this set.
1006
1007 /// Insert the specified `value` into this set if a key equivalent to
1008 /// `value` does not already exist in this set; otherwise, if a key
1009 /// equivalent to `value` already exists in this set, this method has no
1010 /// effect. Return a pair whose `first` member is an iterator referring
1011 /// to the (possibly newly inserted) `value_type` object in this set
1012 /// that is equivalent to `value`, and whose `second` member is `true`
1013 /// if a new value was inserted, and `false` if the key was already
1014 /// present. This method requires that the (template parameter) type
1015 /// `KEY` be `copy-insertable` into this set (see {Requirements on
1016 /// `KEY`}).
1017 pair<iterator, bool> insert(const value_type& value);
1018
1019 /// Insert the specified `value` into this set if a key equivalent to
1020 /// `value` does not already exist in this set; otherwise, if a key
1021 /// equivalent to `value` already exists in this set, this method has no
1022 /// effect. `value` is left in a valid but unspecified state. Return a
1023 /// pair whose `first` member is an iterator referring to the (possibly
1024 /// newly inserted) `value_type` object in this set that is equivalent
1025 /// to `value`, and whose `second` member is `true` if a new value was
1026 /// inserted, and `false` if the key was already present. This method
1027 /// requires that the (template parameter) type `KEY` be
1028 /// `move-insertable` (see {Requirements on `KEY`}).
1030 BloombergLP::bslmf::MovableRef<value_type> value);
1031
1032 /// Insert the specified `value` into this set (in amortized constant
1033 /// time if the specified `hint` is a valid immediate successor to
1034 /// `value`), if a key equivalent to `value` does not already exist in
1035 /// this set; otherwise, if a key equivalent to `value` already exists
1036 /// in this set, this method has no effect. Return an iterator
1037 /// referring to the (possibly newly inserted) `value_type` object in
1038 /// this set that is equivalent to `value`. If `hint` is not a valid
1039 /// immediate successor to `value`, this operation has `O[log(N)]`
1040 /// complexity, where `N` is the size of this set. This method requires
1041 /// that the (template parameter) type `KEY` be `copy-insertable` into
1042 /// this set (see {Requirements on `KEY`}). The behavior is undefined
1043 /// unless `hint` is an iterator in the range `[begin() .. end()]` (both
1044 /// endpoints included).
1046
1047 /// Insert the specified `value` into this set (in amortized constant
1048 /// time if the specified `hint` is a valid immediate successor to
1049 /// `value`) if a key equivalent to `value` does not already exist in
1050 /// this set; otherwise, this method has no effect. `value` is left in
1051 /// a valid but unspecified state. Return an iterator referring to the
1052 /// (possibly newly inserted) `value_type` object in this set that is
1053 /// equivalent to `value`. If `hint` is not a valid immediate successor
1054 /// to `value`, this operation has `O[log(N)]` complexity, where `N` is
1055 /// the size of this set. This method requires that the (template
1056 /// parameter) type `KEY` be `move-insertable` (see {Requirements on
1057 /// `KEY`}). The behavior is undefined unless `hint` is an iterator in
1058 /// the range `[begin() .. end()]` (both endpoints included).
1060 BloombergLP::bslmf::MovableRef<value_type> value);
1061
1062 /// Insert into this set the value of each `value_type` object in the
1063 /// range starting at the specified `first` iterator and ending
1064 /// immediately before the specified `last` iterator, if a key
1065 /// equivalent to the object is not already contained in this set. The
1066 /// (template parameter) type `INPUT_ITERATOR` shall meet the
1067 /// requirements of an input iterator defined in the C++11 standard
1068 /// [24.2.3] providing access to values of a type convertible to
1069 /// `value_type`, and `value_type` must be `emplace-constructible` from
1070 /// `*i` into this set, where `i` is a dereferenceable iterator in the
1071 /// range `[first .. last)` (see {Requirements on `KEY`}). The behavior
1072 /// is undefined unless `first` and `last` refer to a sequence of valid
1073 /// values where `first` is at a position at or before `last`.
1074 template <class INPUT_ITERATOR>
1075 void insert(INPUT_ITERATOR first, INPUT_ITERATOR last);
1076
1077#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1078 /// Insert into this set the value of each `value_type` object in the
1079 /// specified `values` initializer list if a key equivalent to the
1080 /// object is not already contained in this set. This method requires
1081 /// that the (template parameter) type `KEY` be `copy-insertable` (see
1082 /// {Requirements on `KEY`}).
1083 void insert(std::initializer_list<KEY> values);
1084#endif
1085
1086#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1087
1088 /// Insert into this set a newly created `value_type` object,
1089 /// constructed by forwarding `get_allocator()` (if required) and the
1090 /// specified (variable number of) `arguments` to the corresponding
1091 /// constructor of `value_type`, if a key equivalent to such a value
1092 /// does not already exist in this set; otherwise, this method has no
1093 /// effect (other than possibly creating a temporary `value_type`
1094 /// object). Return a pair whose `first` member is an iterator
1095 /// referring to the (possibly newly created and inserted) object in
1096 /// this set whose value is equivalent to that of an object constructed
1097 /// from `arguments`, and whose `second` member is `true` if a new value
1098 /// was inserted, and `false` if an equivalent key was already present.
1099 /// This method requires that the (template parameter) type `KEY` be
1100 /// `emplace-constructible` from `arguments` (see {Requirements on
1101 /// `KEY`}).
1102 template <class... Args>
1103 pair<iterator, bool> emplace(Args&&... arguments);
1104
1105 /// Insert into this set a newly created `value_type` object,
1106 /// constructed by forwarding `get_allocator()` (if required) and the
1107 /// specified (variable number of) `arguments` to the corresponding
1108 /// constructor of `value_type`, (in amortized constant time if the
1109 /// specified `hint` is a valid immediate successor to the `value_type`
1110 /// object constructed from `arguments`), if a key equivalent to such a
1111 /// value does not already exist in this set; otherwise, this method has
1112 /// no effect (other than possibly creating a temporary `value_type`
1113 /// object). Return an iterator referring to the (possibly newly
1114 /// created and inserted) object in this set whose value is equivalent
1115 /// to that of an object constructed from `arguments`. If `hint` is not
1116 /// a valid immediate successor to the `value_type` object implied by
1117 /// `arguments`, this operation has `O[log(N)]` complexity where `N` is
1118 /// the size of this set. This method requires that the (template
1119 /// parameter) type `KEY` be `emplace-constructible` from `arguments`
1120 /// (see {Requirements on `KEY`}). The behavior is undefined unless
1121 /// `hint` is an iterator in the range `[begin() .. end()]` (both
1122 /// endpoints included).
1123 template <class... Args>
1124 iterator emplace_hint(const_iterator hint, Args&&... arguments);
1125
1126#endif
1127
1128 /// Remove from this set the `value_type` object at the specified
1129 /// `position`, and return an iterator referring to the element
1130 /// immediately following the removed element, or to the past-the-end
1131 /// position if the removed element was the last element in the sequence
1132 /// of elements maintained by this set. This method invalidates only
1133 /// iterators and references to the removed element and previously saved
1134 /// values of the `end()` iterator. The behavior is undefined unless
1135 /// `position` refers to a `value_type` object in this set.
1137
1138 /// Remove from this set the `value_type` object that is equivalent to
1139 /// the specified `key`, if such an entry exists, and return 1;
1140 /// otherwise, if there is no `value_type` object that is equivalent to
1141 /// `key`, return 0 with no other effect. This method invalidates only
1142 /// iterators and references to the removed element and previously saved
1143 /// values of the `end()` iterator.
1145
1146 /// Remove from this set the `value_type` objects starting at the
1147 /// specified `first` position up to, but including the specified `last`
1148 /// position, and return `last`. This method invalidates only
1149 /// iterators and references to the removed element and previously saved
1150 /// values of the `end()` iterator. The behavior is undefined unless
1151 /// `first` and `last` either refer to elements in this set or are the
1152 /// `end` iterator, and the `first` position is at or before the `last`
1153 /// position in the ordered sequence provided by this container.
1155
1156 /// Exchange the value and comparator of this object with those of the
1157 /// specified `other` object; also exchange the allocator of this object
1158 /// with that of `other` if the (template parameter) type `ALLOCATOR`
1159 /// has the `propagate_on_container_swap` trait, and do not modify
1160 /// either allocator otherwise. This method provides the no-throw
1161 /// exception-safety guarantee if and only if the (template parameter)
1162 /// type `COMPARATOR` provides a no-throw swap operation, and provides
1163 /// the basic exception-safety guarantee otherwise; if an exception is
1164 /// thrown, both objects are left in valid but unspecified states. This
1165 /// operation has `O[1]` complexity if either this object was created
1166 /// with the same allocator as `other` or `ALLOCATOR` has the
1167 /// `propagate_on_container_swap` trait; otherwise, it has `O[n + m]`
1168 /// complexity, where `n` and `m` are the number of elements in this
1169 /// object and `other`, respectively. Note that this method`s support
1170 /// for swapping objects created with different allocators when
1171 /// `ALLOCATOR` does not have the `propagate_on_container_swap` trait is
1172 /// a departure from the C++ Standard.
1173 void swap(set& other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(
1174 AllocatorTraits::is_always_equal::value
1175 && bsl::is_nothrow_swappable<COMPARATOR>::value);
1176
1177 /// Remove all entries from this set. Note that the set is empty after
1178 /// this call, but allocated memory may be retained for future use.
1180
1181 // Turn off complaints about necessarily class-defined methods.
1182 // BDE_VERIFY pragma: push
1183 // BDE_VERIFY pragma: -CD01
1184
1185 /// Return an iterator providing modifiable access to the `value_type`
1186 /// object in this set that is equivalent to the specified `key`, if
1187 /// such an entry exists, and the past-the-end (`end`) iterator
1188 /// otherwise.
1189 ///
1190 /// Note: implemented inline due to Sun CC compilation error.
1191 iterator find(const key_type& key)
1192 {
1193 return iterator(BloombergLP::bslalg::RbTreeUtil::find(
1194 d_tree, this->comparator(), key));
1195 }
1196
1197 /// Return an iterator providing modifiable access to the `value_type`
1198 /// object in this set that is equivalent to the specified `key`, if
1199 /// such an entry exists, and the past-the-end (`end`) iterator
1200 /// otherwise.
1201 ///
1202 /// Note: implemented inline due to Sun CC compilation error.
1203 template <class LOOKUP_KEY>
1204 typename bsl::enable_if<
1205 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1206 LOOKUP_KEY>::value,
1207 iterator>::type
1208 find(const LOOKUP_KEY& key)
1209 {
1210 return iterator(BloombergLP::bslalg::RbTreeUtil::find(
1211 d_tree, this->comparator(), key));
1212 }
1213
1214 /// Return an iterator providing modifiable access to the first (i.e.,
1215 /// ordered least) `value_type` object in this set greater-than or
1216 /// equal-to the specified `key`, and the past-the-end iterator if this
1217 /// set does not contain a `value_type` object greater-than or equal-to
1218 /// `key`. Note that this function returns the *first* position before
1219 /// which a `value_type` object equivalent to `key` could be inserted
1220 /// into the ordered sequence maintained by this set, while preserving
1221 /// its ordering.
1222 ///
1223 /// Note: implemented inline due to Sun CC compilation error.
1225 {
1226 return iterator(BloombergLP::bslalg::RbTreeUtil::lowerBound(
1227 d_tree, this->comparator(), key));
1228 }
1229
1230 /// Return an iterator providing modifiable access to the first (i.e.,
1231 /// ordered least) `value_type` object in this set greater-than or
1232 /// equal-to the specified `key`, and the past-the-end iterator if this
1233 /// set does not contain a `value_type` object greater-than or equal-to
1234 /// `key`. Note that this function returns the *first* position before
1235 /// which a `value_type` object equivalent to `key` could be inserted
1236 /// into the ordered sequence maintained by this set, while preserving
1237 /// its ordering.
1238 ///
1239 /// Note: implemented inline due to Sun CC compilation error.
1240 template <class LOOKUP_KEY>
1241 typename bsl::enable_if<
1242 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1243 LOOKUP_KEY>::value,
1244 iterator>::type
1245 lower_bound(const LOOKUP_KEY& key)
1246 {
1247 return iterator(BloombergLP::bslalg::RbTreeUtil::lowerBound(
1248 d_tree, this->comparator(), key));
1249 }
1250
1251 /// Return an iterator providing modifiable access to the first (i.e.,
1252 /// ordered least) `value_type` object in this set greater than the
1253 /// specified `key`, and the past-the-end iterator if this set does not
1254 /// contain a `value_type` object greater-than `key`. Note that this
1255 /// function returns the *last* position before which a `value_type`
1256 /// object equivalent to `key` could be inserted into the ordered
1257 /// sequence maintained by this set, while preserving its ordering.
1258 ///
1259 /// Note: implemented inline due to Sun CC compilation error.
1261 {
1262 return iterator(BloombergLP::bslalg::RbTreeUtil::upperBound(
1263 d_tree, this->comparator(), key));
1264 }
1265
1266 /// Return an iterator providing modifiable access to the first (i.e.,
1267 /// ordered least) `value_type` object in this set greater than the
1268 /// specified `key`, and the past-the-end iterator if this set does not
1269 /// contain a `value_type` object greater-than `key`. Note that this
1270 /// function returns the *last* position before which a `value_type`
1271 /// object equivalent to `key` could be inserted into the ordered
1272 /// sequence maintained by this set, while preserving its ordering.
1273 ///
1274 /// Note: implemented inline due to Sun CC compilation error.
1275 template <class LOOKUP_KEY>
1276 typename bsl::enable_if<
1277 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1278 LOOKUP_KEY>::value,
1279 iterator>::type
1280 upper_bound(const LOOKUP_KEY& key)
1281 {
1282 return iterator(BloombergLP::bslalg::RbTreeUtil::upperBound(
1283 d_tree, this->comparator(), key));
1284 }
1285
1286 /// Return a pair of iterators providing modifiable access to the
1287 /// sequence of `value_type` objects in this set that are equivalent to
1288 /// the specified `key`, where the first iterator is positioned at the
1289 /// start of the sequence, and the second is positioned one past the end
1290 /// of the sequence. The first returned iterator will be
1291 /// `lower_bound(key)`; the second returned iterator will be
1292 /// `upper_bound(key)`; and, if this set contains no `value_type`
1293 /// objects equivalent to `key`, then the two returned iterators will
1294 /// have the same value. Note that since a set maintains unique keys,
1295 /// the range will contain at most one element.
1296 ///
1297 /// Note: implemented inline due to Sun CC compilation error.
1299 {
1300 iterator startIt = lower_bound(key);
1301 iterator endIt = startIt;
1302 if (endIt != end() && !comparator()(key, *endIt.node())) {
1303 ++endIt;
1304 }
1305 return pair<iterator, iterator>(startIt, endIt);
1306 }
1307
1308 /// Return a pair of iterators providing modifiable access to the
1309 /// sequence of `value_type` objects in this set that are equivalent to
1310 /// the specified `key`, where the first iterator is positioned at the
1311 /// start of the sequence, and the second is positioned one past the end
1312 /// of the sequence. The first returned iterator will be
1313 /// `lower_bound(key)`; the second returned iterator will be
1314 /// `upper_bound(key)`; and, if this set contains no `value_type`
1315 /// objects equivalent to `key`, then the two returned iterators will
1316 /// have the same value. Note that although a set maintains unique
1317 /// keys, the range may contain more than one element, because a
1318 /// transparent comparator may have been supplied that provides a
1319 /// different (but compatible) partitioning of keys for `LOOKUP_KEY` as
1320 /// the comparisons used to order the keys in the set.
1321 ///
1322 /// Note: implemented inline due to Sun CC compilation error.
1323 template <class LOOKUP_KEY>
1324 typename bsl::enable_if<
1325 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1326 LOOKUP_KEY>::value,
1328 equal_range(const LOOKUP_KEY& key)
1329 {
1330 iterator startIt = lower_bound(key);
1331 iterator endIt = startIt;
1332 if (endIt != end() && !comparator()(key, *endIt.node())) {
1333 ++endIt;
1334
1335 // Typically, even with a transparent comparator, we expect to find
1336 // either 0 or 1 matching keys. We test for those two common cases
1337 // before performing a logarithmic search via @ref upper_bound to
1338 // determine the end of the range.
1339
1340 if (endIt != end() && !comparator()(key, *endIt.node())) {
1341 endIt = upper_bound(key);
1342 }
1343 }
1344 return pair<iterator, iterator>(startIt, endIt);
1345 }
1346
1347 // BDE_VERIFY pragma: pop
1348
1349 // ACCESSORS
1350
1351 /// Return (a copy of) the allocator used for memory allocation by this
1352 /// set.
1354
1355 /// Return an iterator providing non-modifiable access to the first
1356 /// `value_type` object in the ordered sequence of `value_type` objects
1357 /// maintained by this set, or the `end` iterator if this set is empty.
1359
1360 /// Return an iterator providing non-modifiable access to the
1361 /// past-the-end element in the ordered sequence of `value_type`
1362 /// objects maintained by this set.
1364
1365 /// Return a reverse iterator providing non-modifiable access to the
1366 /// last `value_type` object in the ordered sequence of `value_type`
1367 /// objects maintained by this set, or `rend` if this object is empty.
1369
1370 /// Return a reverse iterator providing non-modifiable access to the
1371 /// prior-to-the-beginning element in the ordered sequence of
1372 /// `value_type` objects maintained by this set.
1374
1375 /// Return an iterator providing non-modifiable access to the first
1376 /// `value_type` object in the ordered sequence of `value_type` objects
1377 /// maintained by this set, or the `cend` iterator if this set is empty.
1379
1380 /// Return an iterator providing non-modifiable access to the
1381 /// past-the-end element in the ordered sequence of `value_type` objects
1382 /// maintained by this set.
1384
1385 /// Return a reverse iterator providing non-modifiable access to the
1386 /// last `value_type` object in the ordered sequence of `value_type`
1387 /// objects maintained by this set, or `crend` if this set is empty.
1389
1390 /// Return a reverse iterator providing non-modifiable access to the
1391 /// prior-to-the-beginning element in the ordered sequence of
1392 /// `value_type` objects maintained by this set.
1394
1395 /// Return `true` if this map contains an element whose key is
1396 /// equivalent to the specified `key`.
1397 bool contains(const key_type &key) const;
1398
1399 /// Return `true` if this map contains an element whose key is
1400 /// equivalent to the specified `key`.
1401 ///
1402 /// Note: implemented inline due to Sun CC compilation error
1403 template <class LOOKUP_KEY>
1404 typename bsl::enable_if<
1405 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1406 LOOKUP_KEY>::value,
1407 bool>::type
1408 contains(const LOOKUP_KEY& key) const
1409 {
1410 return find(key) != end();
1411 }
1412
1413 /// Return `true` if this set contains no elements, and `false`
1414 /// otherwise.
1416
1417 /// Return the number of elements in this set.
1419
1420 /// Return a theoretical upper bound on the largest number of elements
1421 /// that this set could possibly hold. Note that there is no guarantee
1422 /// that the set can successfully grow to the returned size, or even
1423 /// close to that size without running out of resources.
1425
1426 /// Return the key-comparison functor (or function pointer) used by this
1427 /// set; if a comparator was supplied at construction, return its value,
1428 /// otherwise return a default constructed @ref key_compare object. Note
1429 /// that this comparator compares objects of type `KEY`, which is the
1430 /// type of the `value_type` objects contained in this set.
1432
1433 /// Return a functor for comparing two `value_type` objects using
1434 /// `key_comp()`. Note that since `value_type` is an alias to `KEY` for
1435 /// `set`, this method returns the same functor as `key_comp()`.
1437
1438 // Turn off complaints about necessarily class-defined methods.
1439 // BDE_VERIFY pragma: push
1440 // BDE_VERIFY pragma: -CD01
1441
1442 /// Return an iterator providing non-modifiable access to the
1443 /// `value_type` object in this set that is equivalent to the specified
1444 /// `key`, if such an entry exists, and the past-the-end (`end`)
1445 /// iterator otherwise.
1446 ///
1447 /// Note: implemented inline due to Sun CC compilation error.
1448 const_iterator find(const key_type& key) const
1449 {
1450 return const_iterator(BloombergLP::bslalg::RbTreeUtil::find(
1451 d_tree, this->comparator(), key));
1452 }
1453
1454 /// Return an iterator providing non-modifiable access to the
1455 /// `value_type` object in this set that is equivalent to the specified
1456 /// `key`, if such an entry exists, and the past-the-end (`end`)
1457 /// iterator otherwise.
1458 ///
1459 /// Note: implemented inline due to Sun CC compilation error.
1460 template <class LOOKUP_KEY>
1461 typename bsl::enable_if<
1462 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1463 LOOKUP_KEY>::value,
1464 const_iterator>::type
1465 find(const LOOKUP_KEY& key) const
1466 {
1467 return const_iterator(BloombergLP::bslalg::RbTreeUtil::find(
1468 d_tree, this->comparator(), key));
1469 }
1470
1471 /// Return the number of `value_type` objects within this set that are
1472 /// equivalent to the specified `key`. Note that since a set maintains
1473 /// unique keys, the returned value will be either 0 or 1.
1474 ///
1475 /// Note: implemented inline due to Sun CC compilation error.
1476 size_type count(const key_type& key) const
1477 {
1478 return (find(key) != end()) ? 1 : 0;
1479 }
1480
1481 /// Return the number of `value_type` objects within this set that are
1482 /// equivalent to the specified `key`. Note that although a set
1483 /// maintains unique keys, the returned value can be other than 0 or 1,
1484 /// because a transparent comparator may have been supplied that
1485 /// provides a different (but compatible) partitioning of keys for
1486 /// `LOOKUP_KEY` as the comparisons used to order the keys in the set.
1487 ///
1488 /// Note: implemented inline due to Sun CC compilation error.
1489 template <class LOOKUP_KEY>
1490 typename bsl::enable_if<
1491 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1492 LOOKUP_KEY>::value,
1493 size_type>::type
1494 count(const LOOKUP_KEY& key) const
1495 {
1496 int count = 0;
1497 const_iterator it = lower_bound(key);
1498
1499 while (it != end() && !comparator()(key, *it.node())) {
1500 ++it;
1501 ++count;
1502 }
1503 return count;
1504 }
1505
1506 /// Return an iterator providing non-modifiable access to the first
1507 /// (i.e., ordered least) `value_type` object in this set greater-than
1508 /// or equal-to the specified `key`, and the past-the-end iterator if
1509 /// this set does not contain a `value_type` greater-than or equal-to
1510 /// `key`. Note that this function returns the *first* position before
1511 /// which a `value_type` object equivalent to `key` could be inserted
1512 /// into the ordered sequence maintained by this set, while preserving
1513 /// its ordering.
1514 ///
1515 /// Note: implemented inline due to Sun CC compilation error.
1517 {
1518 return const_iterator(BloombergLP::bslalg::RbTreeUtil::lowerBound(
1519 d_tree, this->comparator(), key));
1520 }
1521
1522 /// Return an iterator providing non-modifiable access to the first
1523 /// (i.e., ordered least) `value_type` object in this set greater-than
1524 /// or equal-to the specified `key`, and the past-the-end iterator if
1525 /// this set does not contain a `value_type` greater-than or equal-to
1526 /// `key`. Note that this function returns the *first* position before
1527 /// which a `value_type` object equivalent to `key` could be inserted
1528 /// into the ordered sequence maintained by this set, while preserving
1529 /// its ordering.
1530 ///
1531 /// Note: implemented inline due to Sun CC compilation error.
1532 template <class LOOKUP_KEY>
1533 typename bsl::enable_if<
1534 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1535 LOOKUP_KEY>::value,
1536 const_iterator>::type
1537 lower_bound(const LOOKUP_KEY& key) const
1538 {
1539 return const_iterator(BloombergLP::bslalg::RbTreeUtil::lowerBound(
1540 d_tree, this->comparator(), key));
1541 }
1542
1543 /// Return an iterator providing non-modifiable access to the first
1544 /// (i.e., ordered least) `value_type` object in this set greater than
1545 /// the specified `key`, and the past-the-end iterator if this set does
1546 /// not contain a `value_type` object greater-than `key`. Note that
1547 /// this function returns the *last* position before which a
1548 /// `value_type` object equivalent to `key` could be inserted into the
1549 /// ordered sequence maintained by this set, while preserving its
1550 /// ordering.
1551 ///
1552 /// Note: implemented inline due to Sun CC compilation error.
1554 {
1555 return const_iterator(BloombergLP::bslalg::RbTreeUtil::upperBound(
1556 d_tree, this->comparator(), key));
1557 }
1558
1559 /// Return an iterator providing non-modifiable access to the first
1560 /// (i.e., ordered least) `value_type` object in this set greater than
1561 /// the specified `key`, and the past-the-end iterator if this set does
1562 /// not contain a `value_type` object greater-than `key`. Note that
1563 /// this function returns the *last* position before which a
1564 /// `value_type` object equivalent to `key` could be inserted into the
1565 /// ordered sequence maintained by this set, while preserving its
1566 /// ordering.
1567 ///
1568 /// Note: implemented inline due to Sun CC compilation error.
1569 template <class LOOKUP_KEY>
1570 typename bsl::enable_if<
1571 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1572 LOOKUP_KEY>::value,
1573 const_iterator>::type
1574 upper_bound(const LOOKUP_KEY& key) const
1575 {
1576 return const_iterator(BloombergLP::bslalg::RbTreeUtil::upperBound(
1577 d_tree, this->comparator(), key));
1578 }
1579
1580 /// Return a pair of iterators providing non-modifiable access to the
1581 /// sequence of `value_type` objects in this set that are equivalent to
1582 /// the specified `key`, where the first iterator is positioned at the
1583 /// start of the sequence, and the second is positioned one past the end
1584 /// of the sequence. The first returned iterator will be
1585 /// `lower_bound(key)`; the second returned iterator will be
1586 /// `upper_bound(key)`; and, if this set contains no `value_type`
1587 /// objects equivalent to `key`, then the two returned iterators will
1588 /// have the same value. Note that since a set maintains unique keys,
1589 /// the range will contain at most one element.
1590 ///
1591 /// Note: implemented inline due to Sun CC compilation error.
1593 {
1594 const_iterator startIt = lower_bound(key);
1595 const_iterator endIt = startIt;
1596 if (endIt != end() && !comparator()(key, *endIt.node())) {
1597 ++endIt;
1598 }
1599 return pair<const_iterator, const_iterator>(startIt, endIt);
1600 }
1601
1602 /// Return a pair of iterators providing non-modifiable access to the
1603 /// sequence of `value_type` objects in this set that are equivalent to
1604 /// the specified `key`, where the first iterator is positioned at the
1605 /// start of the sequence, and the second is positioned one past the end
1606 /// of the sequence. The first returned iterator will be
1607 /// `lower_bound(key)`; the second returned iterator will be
1608 /// `upper_bound(key)`; and, if this set contains no `value_type`
1609 /// objects equivalent to `key`, then the two returned iterators will
1610 /// have the same value. Note that although a set maintains unique
1611 /// keys, the range may contain more than one element, because a
1612 /// transparent comparator may have been supplied that provides a
1613 /// different (but compatible) partitioning of keys for `LOOKUP_KEY` as
1614 /// the comparisons used to order the keys in the set.
1615 ///
1616 /// Note: implemented inline due to Sun CC compilation error.
1617 template <class LOOKUP_KEY>
1618 typename bsl::enable_if<
1619 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1620 LOOKUP_KEY>::value,
1622 equal_range(const LOOKUP_KEY& key) const
1623 {
1624 const_iterator startIt = lower_bound(key);
1625 const_iterator endIt = startIt;
1626 if (endIt != end() && !comparator()(key, *endIt.node())) {
1627 ++endIt;
1628
1629 // Typically, even with a transparent comparator, we expect to find
1630 // either 0 or 1 matching keys. We test for those two common cases
1631 // before performing a logarithmic search via @ref upper_bound to
1632 // determine the end of the range.
1633
1634 if (endIt != end() && !comparator()(key, *endIt.node())) {
1635 endIt = upper_bound(key);
1636 }
1637 }
1638 return pair<const_iterator, const_iterator>(startIt, endIt);
1639 }
1640
1641 // BDE_VERIFY pragma: pop
1642};
1643
1644#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
1645// CLASS TEMPLATE DEDUCTION GUIDES
1646
1647/// Deduce the template parameter `KEY` from the `value_type` of the
1648/// iterators supplied to the constructor of `set`. Deduce the template
1649/// parameters `COMPARATOR` and `ALLOCATOR` from the other parameters passed
1650/// to the constructor. This guide does not participate unless the
1651/// supplied (or defaulted) `ALLOCATOR` meets the requirements of a
1652/// standard allocator.
1653template <
1654 class INPUT_ITERATOR,
1655 class KEY = typename bsl::iterator_traits<INPUT_ITERATOR>::value_type,
1656 class COMPARATOR = std::less<KEY>,
1657 class ALLOCATOR = bsl::allocator<KEY>,
1658 class = bsl::enable_if_t<!bsl::IsStdAllocator_v<COMPARATOR>>,
1659 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
1660 >
1661set(INPUT_ITERATOR,
1662 INPUT_ITERATOR,
1663 COMPARATOR = COMPARATOR(),
1664 ALLOCATOR = ALLOCATOR())
1665-> set<KEY, COMPARATOR, ALLOCATOR>;
1666
1667/// Deduce the template parameter `KEY` from the `value_type` of the
1668/// iterators supplied to the constructor of `set`. Deduce the template
1669/// parameter `COMPARATOR` from the other parameter passed to the
1670/// constructor. This deduction guide does not participate unless the
1671/// specified `ALLOC` is convertible to `bsl::allocator<KEY>`.
1672template <
1673 class INPUT_ITERATOR,
1674 class COMPARATOR,
1675 class ALLOC,
1676 class KEY =
1677 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
1678 class DEFAULT_ALLOCATOR = bsl::allocator<KEY>,
1679 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1680 >
1681set(INPUT_ITERATOR, INPUT_ITERATOR, COMPARATOR, ALLOC *)
1682-> set<KEY, COMPARATOR>;
1683
1684/// Deduce the template parameter `KEY` from the `value_type` of the
1685/// iterators supplied to the constructor of `set`. Deduce the template
1686/// parameter `ALLOCATOR` from the other parameter passed to the
1687/// constructor. This deduction guide does not participate unless the
1688/// supplied allocator meets the requirements of a standard allocator.
1689template <
1690 class INPUT_ITERATOR,
1691 class ALLOCATOR,
1692 class KEY =
1693 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
1694 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
1695 >
1696set(INPUT_ITERATOR, INPUT_ITERATOR, ALLOCATOR)
1697-> set<KEY, std::less<KEY>, ALLOCATOR>;
1698
1699/// Deduce the template parameter `KEY` from the `value_type` of the
1700/// iterators supplied to the constructor of `set`. This deduction guide
1701/// does not participate unless the specified `ALLOC` is convertible to
1702/// `bsl::allocator<KEY>`.
1703template <
1704 class INPUT_ITERATOR,
1705 class ALLOC,
1706 class KEY =
1707 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
1708 class DEFAULT_ALLOCATOR = bsl::allocator<KEY>,
1709 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1710 >
1711set(INPUT_ITERATOR, INPUT_ITERATOR, ALLOC *)
1712-> set<KEY>;
1713
1714/// Deduce the template parameter `KEY` from the `value_type` of the
1715/// initializer_list supplied to the constructor of `set`. Deduce the
1716/// template parameters `COMPARATOR` and `ALLOCATOR` from the other
1717/// parameters passed to the constructor.
1718template <
1719 class KEY,
1720 class COMPARATOR = std::less<KEY>,
1721 class ALLOCATOR = bsl::allocator<KEY>,
1722 class = bsl::enable_if_t<!bsl::IsStdAllocator_v<COMPARATOR>>,
1723 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
1724 >
1725set(std::initializer_list<KEY>,
1726 COMPARATOR = COMPARATOR(),
1727 ALLOCATOR = ALLOCATOR())
1728-> set<KEY, COMPARATOR, ALLOCATOR>;
1729
1730/// Deduce the template parameter `KEY` from the `value_type` of the
1731/// initializer_list supplied to the constructor of `set`. Deduce the
1732/// template parameter `COMPARATOR` from the other parameter passed to the
1733/// constructor. This deduction guide does not participate unless the
1734/// specified `ALLOC` is convertible to `bsl::allocator<KEY>`.
1735template <
1736 class KEY,
1737 class COMPARATOR,
1738 class ALLOC,
1739 class DEFAULT_ALLOCATOR = bsl::allocator<KEY>,
1740 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1741 >
1742set(std::initializer_list<KEY>, COMPARATOR, ALLOC *)
1743-> set<KEY, COMPARATOR>;
1744
1745/// Deduce the template parameter `KEY` from the `value_type` of the
1746/// initializer_list supplied to the constructor of `set`. Deduce the
1747/// template parameter `ALLOCATOR` from the other parameter passed to the
1748/// constructor.
1749template <
1750 class KEY,
1751 class ALLOCATOR,
1752 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
1753 >
1754set(std::initializer_list<KEY>, ALLOCATOR)
1755-> set<KEY, std::less<KEY>, ALLOCATOR>;
1756
1757/// Deduce the template parameter `KEY` from the `value_type` of the
1758/// initializer_list supplied to the constructor of `set`. This deduction
1759/// guide does not participate unless the specified `ALLOC` is convertible
1760/// to `bsl::allocator<KEY>`.
1761template <
1762 class KEY,
1763 class ALLOC,
1764 class DEFAULT_ALLOCATOR = bsl::allocator<KEY>,
1765 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1766 >
1767set(std::initializer_list<KEY>, ALLOC *)
1768-> set<KEY>;
1769
1770#endif
1771
1772// FREE OPERATORS
1773
1774/// Return `true` if the specified `lhs` and `rhs` objects have the same
1775/// value, and `false` otherwise. Two `set` objects `lhs` and `rhs` have
1776/// the same value if they have the same number of keys, and each element
1777/// in the ordered sequence of keys of `lhs` has the same value as the
1778/// corresponding element in the ordered sequence of keys of `rhs`. This
1779/// method requires that the (template parameter) type `KEY` be
1780/// `equality-comparable` (see {Requirements on `KEY`}).
1781template <class KEY, class COMPARATOR, class ALLOCATOR>
1782bool operator==(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1783 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1784
1785#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
1786/// Return `true` if the specified `lhs` and `rhs` objects do not have the
1787/// same value, and `false` otherwise. Two `set` objects `lhs` and `rhs` do
1788/// not have the same value if they do not have the same number of keys, or
1789/// some element in the ordered sequence of keys of `lhs` does not have the
1790/// same value as the corresponding element in the ordered sequence of keys
1791/// of `rhs`. This method requires that the (template parameter) type `KEY`
1792/// be `equality-comparable` (see {Requirements on `KEY`}).
1793template <class KEY, class COMPARATOR, class ALLOCATOR>
1794bool operator!=(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1795 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1796#endif
1797
1798#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
1799
1800/// Perform a lexicographic three-way comparison of the specified `lhs` and
1801/// the specified `rhs` sets by using the comparison operators of `KEY` on
1802/// each element; return the result of that comparison.
1803template <class KEY, class COMPARATOR, class ALLOCATOR>
1804BloombergLP::bslalg::SynthThreeWayUtil::Result<KEY>
1805operator<=>(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1806 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1807
1808#else
1809
1810/// Return `true` if the value of the specified `lhs` set is
1811/// lexicographically less than that of the specified `rhs` set, and `false`
1812/// otherwise. Given iterators `i` and `j` over the respective sequences
1813/// `[lhs.begin() .. lhs.end())` and `[rhs.begin() .. rhs.end())`, the value
1814/// of set `lhs` is lexicographically less than that of set `rhs` if
1815/// `true == *i < *j` for the first pair of corresponding iterator positions
1816/// where `*i < *j` and `*j < *i` are not both `false`. If no such
1817/// corresponding iterator position exists, the value of `lhs` is
1818/// lexicographically less than that of `rhs` if `lhs.size() < rhs.size()`.
1819/// This method requires that `operator<`, inducing a total order, be
1820/// defined for `value_type`.
1821template <class KEY, class COMPARATOR, class ALLOCATOR>
1822bool operator< (const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1823 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1824
1825/// Return `true` if the value of the specified `lhs` set is
1826/// lexicographically greater than that of the specified `rhs` set, and
1827/// `false` otherwise. The value of set `lhs` is lexicographically greater
1828/// than that of set `rhs` if `rhs` is lexicographically less than `lhs`
1829/// (see `operator<`). This method requires that `operator<`, inducing a
1830/// total order, be defined for `value_type`. Note that this operator
1831/// returns `rhs < lhs`.
1832template <class KEY, class COMPARATOR, class ALLOCATOR>
1833bool operator> (const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1834 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1835
1836/// Return `true` if the value of the specified `lhs` set is
1837/// lexicographically less than or equal to that of the specified `rhs` set,
1838/// and `false` otherwise. The value of set `lhs` is lexicographically less
1839/// than or equal to that of set `rhs` if `rhs` is not lexicographically
1840/// less than `lhs` (see `operator<`). This method requires that
1841/// `operator<`, inducing a total order, be defined for `value_type`. Note
1842/// that this operator returns `!(rhs < lhs)`.
1843template <class KEY, class COMPARATOR, class ALLOCATOR>
1844bool operator<=(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1845 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1846
1847/// Return `true` if the value of the specified `lhs` set is
1848/// lexicographically greater than or equal to that of the specified `rhs`
1849/// set, and `false` otherwise. The value of set `lhs` is lexicographically
1850/// greater than or equal to that of set `rhs` if `lhs` is not
1851/// lexicographically less than `rhs` (see `operator<`). This method
1852/// requires that `operator<`, inducing a total order, be defined for
1853/// `value_type`. Note that this operator returns `!(lhs < rhs)`.
1854template <class KEY, class COMPARATOR, class ALLOCATOR>
1855bool operator>=(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1856 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1857
1858#endif // BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
1859
1860// FREE FUNCTIONS
1861
1862/// Erase all the elements in the specified set `s` that satisfy the
1863/// specified predicate `predicate`. Return the number of elements erased.
1864template <class KEY, class COMPARATOR, class ALLOCATOR, class PREDICATE>
1865typename set<KEY, COMPARATOR, ALLOCATOR>::size_type
1866erase_if(set<KEY, COMPARATOR, ALLOCATOR>& s, PREDICATE predicate);
1867
1868/// Exchange the value and comparator of the specified `a` object with those
1869/// of the specified `b` object; also exchange the allocator of `a` with
1870/// that of `b` if the (template parameter) type `ALLOCATOR` has the
1871/// `propagate_on_container_swap` trait, and do not modify either allocator
1872/// otherwise. This function provides the no-throw exception-safety
1873/// guarantee if and only if the (template parameter) type `COMPARATOR`
1874/// provides a no-throw swap operation, and provides the basic
1875/// exception-safety guarantee otherwise; if an exception is thrown, both
1876/// objects are left in valid but unspecified states. This operation has
1877/// `O[1]` complexity if either `a` was created with the same allocator as
1878/// `b` or `ALLOCATOR` has the `propagate_on_container_swap` trait;
1879/// otherwise, it has `O[n + m]` complexity, where `n` and `m` are the
1880/// number of elements in `a` and `b`, respectively. Note that this
1881/// function`s support for swapping objects created with different
1882/// allocators when `ALLOCATOR` does not have the
1883/// `propagate_on_container_swap` trait is a departure from the C++
1884/// Standard.
1885template <class KEY, class COMPARATOR, class ALLOCATOR>
1886void swap(set<KEY, COMPARATOR, ALLOCATOR>& a,
1887 set<KEY, COMPARATOR, ALLOCATOR>& b)
1889 BSLS_KEYWORD_NOEXCEPT_OPERATOR(a.swap(b)));
1890
1891// ============================================================================
1892// TEMPLATE AND INLINE FUNCTION DEFINITIONS
1893// ============================================================================
1894
1895 // -----------------
1896 // class DataWrapper
1897 // -----------------
1898
1899// CREATORS
1900template <class KEY, class COMPARATOR, class ALLOCATOR>
1901inline
1902set<KEY, COMPARATOR, ALLOCATOR>::DataWrapper::DataWrapper(
1903 const COMPARATOR& comparator,
1904 const ALLOCATOR& basicAllocator)
1905: ::bsl::set<KEY, COMPARATOR, ALLOCATOR>::Comparator(comparator)
1906, d_pool(basicAllocator)
1907{
1908}
1909
1910template <class KEY, class COMPARATOR, class ALLOCATOR>
1911inline
1912set<KEY, COMPARATOR, ALLOCATOR>::DataWrapper::DataWrapper(
1913 BloombergLP::bslmf::MovableRef<DataWrapper> original)
1914: ::bsl::set<KEY, COMPARATOR, ALLOCATOR>::Comparator(
1915 MoveUtil::access(original).keyComparator())
1916, d_pool(MoveUtil::move(MoveUtil::access(original).d_pool))
1917{
1918}
1919
1920template <class KEY, class COMPARATOR, class ALLOCATOR>
1921inline
1922typename set<KEY, COMPARATOR, ALLOCATOR>::NodeFactory&
1923set<KEY, COMPARATOR, ALLOCATOR>::DataWrapper::nodeFactory()
1924{
1925 return d_pool;
1926}
1927
1928template <class KEY, class COMPARATOR, class ALLOCATOR>
1929inline
1930const typename set<KEY, COMPARATOR, ALLOCATOR>::NodeFactory&
1931set<KEY, COMPARATOR, ALLOCATOR>::DataWrapper::nodeFactory() const
1932{
1933 return d_pool;
1934}
1935
1936 // ---------
1937 // class set
1938 // ---------
1939
1940// PRIVATE MANIPULATORS
1941template <class KEY, class COMPARATOR, class ALLOCATOR>
1942inline
1943typename set<KEY, COMPARATOR, ALLOCATOR>::NodeFactory&
1944set<KEY, COMPARATOR, ALLOCATOR>::nodeFactory()
1945{
1946 return d_compAndAlloc.nodeFactory();
1947}
1948
1949template <class KEY, class COMPARATOR, class ALLOCATOR>
1950inline
1951typename set<KEY, COMPARATOR, ALLOCATOR>::Comparator&
1952set<KEY, COMPARATOR, ALLOCATOR>::comparator()
1953{
1954 return d_compAndAlloc;
1955}
1956
1957template <class KEY, class COMPARATOR, class ALLOCATOR>
1958inline
1959void set<KEY, COMPARATOR, ALLOCATOR>::quickSwapExchangeAllocators(set& other)
1960{
1961 BloombergLP::bslalg::RbTreeUtil::swap(&d_tree, &other.d_tree);
1962 nodeFactory().swapExchangeAllocators(other.nodeFactory());
1963
1964 // `DataWrapper` contains a `NodeFactory` object and inherits from
1965 // `Comparator`. If the empty-base-class optimization has been applied to
1966 // `Comparator`, then we must not call `swap` on it because
1967 // `sizeof(Comparator) > 0` and, therefore, we will incorrectly swap bytes
1968 // of the `NodeFactory` members!
1969
1970 if (sizeof(NodeFactory) != sizeof(DataWrapper)) {
1971 comparator().swap(other.comparator());
1972 }
1973}
1974
1975template <class KEY, class COMPARATOR, class ALLOCATOR>
1976inline
1977void set<KEY, COMPARATOR, ALLOCATOR>::quickSwapRetainAllocators(set& other)
1978{
1979 BloombergLP::bslalg::RbTreeUtil::swap(&d_tree, &other.d_tree);
1980 nodeFactory().swapRetainAllocators(other.nodeFactory());
1981
1982 // See `quickSwapExchangeAllocators` (above).
1983
1984 if (sizeof(NodeFactory) != sizeof(DataWrapper)) {
1985 comparator().swap(other.comparator());
1986 }
1987}
1988
1989// PRIVATE ACCESSORS
1990template <class KEY, class COMPARATOR, class ALLOCATOR>
1991inline
1992const typename set<KEY, COMPARATOR, ALLOCATOR>::NodeFactory&
1993set<KEY, COMPARATOR, ALLOCATOR>::nodeFactory() const
1994{
1995 return d_compAndAlloc.nodeFactory();
1996}
1997
1998template <class KEY, class COMPARATOR, class ALLOCATOR>
1999inline
2000const typename set<KEY, COMPARATOR, ALLOCATOR>::Comparator&
2001set<KEY, COMPARATOR, ALLOCATOR>::comparator() const
2002{
2003 return d_compAndAlloc;
2004}
2005
2006// CREATORS
2007template <class KEY, class COMPARATOR, class ALLOCATOR>
2008inline
2010: d_compAndAlloc(COMPARATOR(), ALLOCATOR())
2011, d_tree()
2012{
2013}
2014
2015template <class KEY, class COMPARATOR, class ALLOCATOR>
2016inline
2017set<KEY, COMPARATOR, ALLOCATOR>::set(const ALLOCATOR& basicAllocator)
2018: d_compAndAlloc(COMPARATOR(), basicAllocator)
2019, d_tree()
2020{
2021}
2022
2023template <class KEY, class COMPARATOR, class ALLOCATOR>
2024inline
2026: d_compAndAlloc(original.comparator().keyComparator(),
2027 AllocatorTraits::select_on_container_copy_construction(
2028 original.nodeFactory().allocator()))
2029, d_tree()
2030{
2031 if (0 < original.size()) {
2032 nodeFactory().reserveNodes(original.size());
2033 BloombergLP::bslalg::RbTreeUtil::copyTree(&d_tree,
2034 original.d_tree,
2035 &nodeFactory());
2036 }
2037}
2038
2039template <class KEY, class COMPARATOR, class ALLOCATOR>
2040inline
2042 BloombergLP::bslmf::MovableRef<set> original)
2043: d_compAndAlloc(MoveUtil::move(MoveUtil::access(original).d_compAndAlloc))
2044, d_tree()
2045{
2046 set& lvalue = original;
2047 BloombergLP::bslalg::RbTreeUtil::swap(&d_tree, &lvalue.d_tree);
2048}
2049
2050template <class KEY, class COMPARATOR, class ALLOCATOR>
2051inline
2053 const set& original,
2054 const typename type_identity<ALLOCATOR>::type& basicAllocator)
2055: d_compAndAlloc(original.comparator().keyComparator(), basicAllocator)
2056, d_tree()
2057{
2058 if (0 < original.size()) {
2059 nodeFactory().reserveNodes(original.size());
2060 BloombergLP::bslalg::RbTreeUtil::copyTree(&d_tree,
2061 original.d_tree,
2062 &nodeFactory());
2063 }
2064}
2065
2066template <class KEY, class COMPARATOR, class ALLOCATOR>
2067inline
2069 BloombergLP::bslmf::MovableRef<set> original,
2070 const typename type_identity<ALLOCATOR>::type& basicAllocator)
2071: d_compAndAlloc(MoveUtil::access(original).comparator().keyComparator(),
2072 basicAllocator)
2073, d_tree()
2074{
2075 set& lvalue = original;
2076
2078 nodeFactory().allocator() == lvalue.nodeFactory().allocator())) {
2079 d_compAndAlloc.nodeFactory().adopt(
2080 MoveUtil::move(lvalue.d_compAndAlloc.nodeFactory()));
2081 BloombergLP::bslalg::RbTreeUtil::swap(&d_tree, &lvalue.d_tree);
2082 }
2083 else {
2084 if (0 < lvalue.size()) {
2085 nodeFactory().reserveNodes(lvalue.size());
2086 BloombergLP::bslalg::RbTreeUtil::moveTree(&d_tree,
2087 &lvalue.d_tree,
2088 &nodeFactory(),
2089 &lvalue.nodeFactory());
2090 }
2091 }
2092}
2093
2094template <class KEY, class COMPARATOR, class ALLOCATOR>
2095template <class INPUT_ITERATOR>
2096inline
2098 INPUT_ITERATOR last,
2099 const COMPARATOR& comparator,
2100 const ALLOCATOR& basicAllocator)
2101: d_compAndAlloc(comparator, basicAllocator)
2102, d_tree()
2103{
2104 if (first != last) {
2105
2106 size_type numElements =
2107 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last);
2108
2109 if (0 < numElements) {
2110 nodeFactory().reserveNodes(numElements);
2111 }
2112
2113 BloombergLP::bslalg::RbTreeUtilTreeProctor<NodeFactory> proctor(
2114 &d_tree,
2115 &nodeFactory());
2116
2117 // The following loop guarantees amortized linear time to insert an
2118 // ordered sequence of values (as required by the standard). If the
2119 // values are in sorted order, we are guaranteed the next node can be
2120 // inserted as the right child of the previous node, and can call
2121 // `insertAt` without `findUniqueInsertLocation`.
2122
2123 insert(*first);
2124 BloombergLP::bslalg::RbTreeNode *prevNode = d_tree.rootNode();
2125 while (++first != last) {
2126 // The values are not in order, so insert them normally.
2127
2128 const value_type& value = *first;
2129 if (this->comparator()(value, *prevNode)) {
2130 insert(value);
2131 insert(++first, last);
2132 break;
2133 }
2134
2135 if (this->comparator()(*prevNode, value)) {
2136 BloombergLP::bslalg::RbTreeNode *node =
2137 nodeFactory().emplaceIntoNewNode(value);
2138 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2139 prevNode,
2140 false,
2141 node);
2142 prevNode = node;
2143 }
2144 }
2145
2146 proctor.release();
2147 }
2148}
2149
2150template <class KEY, class COMPARATOR, class ALLOCATOR>
2151template <class INPUT_ITERATOR>
2152inline
2154 INPUT_ITERATOR last,
2155 const ALLOCATOR& basicAllocator)
2156: d_compAndAlloc(COMPARATOR(), basicAllocator)
2157, d_tree()
2158{
2159 if (first != last) {
2160
2161 size_type numElements =
2162 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last);
2163
2164 if (0 < numElements) {
2165 nodeFactory().reserveNodes(numElements);
2166 }
2167
2168 BloombergLP::bslalg::RbTreeUtilTreeProctor<NodeFactory> proctor(
2169 &d_tree,
2170 &nodeFactory());
2171
2172 // The following loop guarantees amortized linear time to insert an
2173 // ordered sequence of values (as required by the standard). If the
2174 // values are in sorted order, we are guaranteed the next node can be
2175 // inserted as the right child of the previous node, and can call
2176 // `insertAt` without `findUniqueInsertLocation`.
2177
2178 insert(*first);
2179 BloombergLP::bslalg::RbTreeNode *prevNode = d_tree.rootNode();
2180 while (++first != last) {
2181 // The values are not in order, so insert them normally.
2182
2183 const value_type& value = *first;
2184 if (this->comparator()(value, *prevNode)) {
2185 insert(value);
2186 insert(++first, last);
2187 break;
2188 }
2189
2190 if (this->comparator()(*prevNode, value)) {
2191 BloombergLP::bslalg::RbTreeNode *node =
2192 nodeFactory().emplaceIntoNewNode(value);
2193 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2194 prevNode,
2195 false,
2196 node);
2197 prevNode = node;
2198 }
2199 }
2200
2201 proctor.release();
2202 }
2203}
2204
2205#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2206template <class KEY, class COMPARATOR, class ALLOCATOR>
2207inline
2208set<KEY, COMPARATOR, ALLOCATOR>::set(std::initializer_list<KEY> values,
2209 const COMPARATOR& comparator,
2210 const ALLOCATOR& basicAllocator)
2211: set(values.begin(), values.end(), comparator, basicAllocator)
2212{
2213}
2214
2215template <class KEY, class COMPARATOR, class ALLOCATOR>
2216inline
2217set<KEY, COMPARATOR, ALLOCATOR>::set(std::initializer_list<KEY> values,
2218 const ALLOCATOR& basicAllocator)
2219: set(values.begin(), values.end(), COMPARATOR(), basicAllocator)
2220{
2221}
2222#endif
2223
2224template <class KEY, class COMPARATOR, class ALLOCATOR>
2225inline
2227{
2228 clear();
2229}
2230
2231// MANIPULATORS
2232template <class KEY, class COMPARATOR, class ALLOCATOR>
2233inline
2236{
2237 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this != &rhs)) {
2238 if (AllocatorTraits::propagate_on_container_copy_assignment::value) {
2239 set other(rhs, rhs.nodeFactory().allocator());
2240 quickSwapExchangeAllocators(other);
2241 }
2242 else {
2243 set other(rhs, nodeFactory().allocator());
2244 quickSwapRetainAllocators(other);
2245 }
2246 }
2247 return *this;
2248}
2249
2250template <class KEY, class COMPARATOR, class ALLOCATOR>
2251inline
2254 BloombergLP::bslmf::MovableRef<set> rhs)
2256 AllocatorTraits::is_always_equal::value
2257 && std::is_nothrow_move_assignable<COMPARATOR>::value)
2258{
2259 set& lvalue = rhs;
2260
2261 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this != &lvalue)) {
2262 if (nodeFactory().allocator() == lvalue.nodeFactory().allocator()) {
2263 set other(MoveUtil::move(lvalue));
2264 quickSwapRetainAllocators(other);
2265 }
2266 else if (
2267 AllocatorTraits::propagate_on_container_move_assignment::value) {
2268 set other(MoveUtil::move(lvalue));
2269 quickSwapExchangeAllocators(other);
2270 }
2271 else {
2272 set other(MoveUtil::move(lvalue), nodeFactory().allocator());
2273 quickSwapRetainAllocators(other);
2274 }
2275 }
2276 return *this;
2277}
2278
2279#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2280template <class KEY, class COMPARATOR, class ALLOCATOR>
2281inline
2282set<KEY, COMPARATOR, ALLOCATOR>&
2283set<KEY, COMPARATOR, ALLOCATOR>::operator=(std::initializer_list<KEY> values)
2284{
2285 clear();
2286 insert(values.begin(), values.end());
2287 return *this;
2288}
2289#endif
2290
2291template <class KEY, class COMPARATOR, class ALLOCATOR>
2292inline
2295{
2296 return iterator(d_tree.firstNode());
2297}
2298
2299template <class KEY, class COMPARATOR, class ALLOCATOR>
2300inline
2303{
2304 return iterator(d_tree.sentinel());
2305}
2306
2307template <class KEY, class COMPARATOR, class ALLOCATOR>
2308inline
2314
2315template <class KEY, class COMPARATOR, class ALLOCATOR>
2316inline
2322
2323template <class KEY, class COMPARATOR, class ALLOCATOR>
2324inline
2327{
2328 int comparisonResult;
2329 BloombergLP::bslalg::RbTreeNode *insertLocation =
2330 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2331 &comparisonResult,
2332 &d_tree,
2333 this->comparator(),
2334 value);
2335 if (!comparisonResult) {
2336 return pair<iterator, bool>(iterator(insertLocation), false);
2337 // RETURN
2338 }
2339 BloombergLP::bslalg::RbTreeNode *node =
2340 nodeFactory().emplaceIntoNewNode(value);
2341 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2342 insertLocation,
2343 comparisonResult < 0,
2344 node);
2345 return pair<iterator, bool>(iterator(node), true);
2346}
2347
2348template <class KEY, class COMPARATOR, class ALLOCATOR>
2349inline
2352 BloombergLP::bslmf::MovableRef<value_type> value)
2353{
2354 value_type& lvalue = value;
2355 int comparisonResult;
2356 BloombergLP::bslalg::RbTreeNode *insertLocation =
2357 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2358 &comparisonResult,
2359 &d_tree,
2360 this->comparator(),
2361 lvalue);
2362 if (!comparisonResult) {
2363 return pair<iterator, bool>(iterator(insertLocation), false);
2364 // RETURN
2365 }
2366 BloombergLP::bslalg::RbTreeNode *node =
2367 nodeFactory().emplaceIntoNewNode(MoveUtil::move(lvalue));
2368 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2369 insertLocation,
2370 comparisonResult < 0,
2371 node);
2372 return pair<iterator, bool>(iterator(node), true);
2373}
2374
2375template <class KEY, class COMPARATOR, class ALLOCATOR>
2376inline
2379 const value_type& value)
2380{
2381 BloombergLP::bslalg::RbTreeNode *hintNode =
2382 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
2383 int comparisonResult;
2384 BloombergLP::bslalg::RbTreeNode *insertLocation =
2385 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2386 &comparisonResult,
2387 &d_tree,
2388 this->comparator(),
2389 value,
2390 hintNode);
2391 if (!comparisonResult) {
2392 return iterator(insertLocation); // RETURN
2393 }
2394
2395 BloombergLP::bslalg::RbTreeNode *node =
2396 nodeFactory().emplaceIntoNewNode(value);
2397 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2398 insertLocation,
2399 comparisonResult < 0,
2400 node);
2401 return iterator(node);
2402}
2403
2404template <class KEY, class COMPARATOR, class ALLOCATOR>
2405inline
2408 BloombergLP::bslmf::MovableRef<value_type> value)
2409{
2410 value_type& lvalue = value;
2411 BloombergLP::bslalg::RbTreeNode *hintNode =
2412 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
2413 int comparisonResult;
2414 BloombergLP::bslalg::RbTreeNode *insertLocation =
2415 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2416 &comparisonResult,
2417 &d_tree,
2418 this->comparator(),
2419 lvalue,
2420 hintNode);
2421 if (!comparisonResult) {
2422 return iterator(insertLocation); // RETURN
2423 }
2424
2425 BloombergLP::bslalg::RbTreeNode *node =
2426 nodeFactory().emplaceIntoNewNode(MoveUtil::move(lvalue));
2427
2428 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2429 insertLocation,
2430 comparisonResult < 0,
2431 node);
2432 return iterator(node);
2433}
2434
2435template <class KEY, class COMPARATOR, class ALLOCATOR>
2436template <class INPUT_ITERATOR>
2437inline
2439 INPUT_ITERATOR last)
2440{
2441 ///Implementation Notes
2442 ///--------------------
2443 // First, consume currently held free nodes. If those nodes are
2444 // insufficient *and* one can calculate the remaining number of elements,
2445 // then reserve exactly that many free nodes. There is no more than one
2446 // call to `reserveNodes` per invocation of this method, hence the use of
2447 // `BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY`. When reserving nodes, we
2448 // assume the elements remaining to be inserted are unique and do not
2449 // duplicate any elements already in the container. If there are any
2450 // duplicates, this container will have free nodes on return from this
2451 // method.
2452
2453 const bool canCalculateInsertDistance =
2454 is_convertible<typename
2455 iterator_traits<INPUT_ITERATOR>::iterator_category,
2456 forward_iterator_tag>::value;
2457
2458 while (first != last) {
2459 if (canCalculateInsertDistance
2461 !nodeFactory().hasFreeNodes())) {
2462 const size_type numElements =
2463 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last);
2464
2465 nodeFactory().reserveNodes(numElements);
2466 }
2467 insert(*first);
2468 ++first;
2469 }
2470}
2471
2472#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2473template <class KEY, class COMPARATOR, class ALLOCATOR>
2474inline
2475void set<KEY, COMPARATOR, ALLOCATOR>::insert(std::initializer_list<KEY> values)
2476{
2477 insert(values.begin(), values.end());
2478}
2479#endif
2480
2481#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
2482template <class KEY, class COMPARATOR, class ALLOCATOR>
2483template <class... Args>
2484inline
2485pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2487{
2488 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2489 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
2490 int comparisonResult;
2491 BloombergLP::bslalg::RbTreeNode *insertLocation =
2492 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2493 &comparisonResult,
2494 &d_tree,
2495 this->comparator(),
2496 static_cast<const Node *>(node)->value());
2497 if (!comparisonResult) {
2498 nodeFactory().deleteNode(node);
2499 return pair<iterator, bool>(iterator(insertLocation), false);
2500 // RETURN
2501 }
2502 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2503 insertLocation,
2504 comparisonResult < 0,
2505 node);
2506 return pair<iterator, bool>(iterator(node), true);
2507}
2508
2509template <class KEY, class COMPARATOR, class ALLOCATOR>
2510template <class... Args>
2511inline
2514 Args&&... arguments)
2515{
2516 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2517 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
2518 BloombergLP::bslalg::RbTreeNode *hintNode =
2519 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
2520 int comparisonResult;
2521 BloombergLP::bslalg::RbTreeNode *insertLocation =
2522 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2523 &comparisonResult,
2524 &d_tree,
2525 this->comparator(),
2526 static_cast<const Node *>(node)->value(),
2527 hintNode);
2528 if (!comparisonResult) {
2529 nodeFactory().deleteNode(node);
2530 return iterator(insertLocation); // RETURN
2531 }
2532
2533 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2534 insertLocation,
2535 comparisonResult < 0,
2536 node);
2537 return iterator(node);
2538}
2539#endif
2540
2541template <class KEY, class COMPARATOR, class ALLOCATOR>
2542inline
2545{
2546 BSLS_ASSERT_SAFE(position != end());
2547
2548 BloombergLP::bslalg::RbTreeNode *node =
2549 const_cast<BloombergLP::bslalg::RbTreeNode *>(position.node());
2550 BloombergLP::bslalg::RbTreeNode *result =
2551 BloombergLP::bslalg::RbTreeUtil::next(node);
2552 BloombergLP::bslalg::RbTreeUtil::remove(&d_tree, node);
2553 nodeFactory().deleteNode(node);
2554 return iterator(result);
2555}
2556
2557template <class KEY, class COMPARATOR, class ALLOCATOR>
2558inline
2561{
2562 const_iterator it = find(key);
2563 if (it == end()) {
2564 return 0; // RETURN
2565 }
2566 erase(it);
2567 return 1;
2568}
2569
2570template <class KEY, class COMPARATOR, class ALLOCATOR>
2571inline
2574 const_iterator last)
2575{
2576 while (first != last) {
2577 first = erase(first);
2578 }
2579 return iterator(last.node());
2580}
2581
2582template <class KEY, class COMPARATOR, class ALLOCATOR>
2583inline
2586 AllocatorTraits::is_always_equal::value
2587 && bsl::is_nothrow_swappable<COMPARATOR>::value)
2588{
2589 if (AllocatorTraits::propagate_on_container_swap::value) {
2590 quickSwapExchangeAllocators(other);
2591 }
2592 else {
2593 // C++11 behavior for member `swap`: undefined for unequal allocators.
2594 // BSLS_ASSERT(allocator() == other.allocator());
2595
2597 nodeFactory().allocator() == other.nodeFactory().allocator())) {
2598 quickSwapRetainAllocators(other);
2599 }
2600 else {
2602
2603 set toOtherCopy(MoveUtil::move(*this),
2604 other.nodeFactory().allocator());
2605 set toThisCopy(MoveUtil::move(other), nodeFactory().allocator());
2606
2607 this->quickSwapRetainAllocators(toThisCopy);
2608 other.quickSwapRetainAllocators(toOtherCopy);
2609 }
2610 }
2611}
2612
2613template <class KEY, class COMPARATOR, class ALLOCATOR>
2614inline
2616{
2617 BSLS_ASSERT_SAFE(d_tree.firstNode());
2618
2619 if (d_tree.rootNode()) {
2620 BSLS_ASSERT_SAFE(0 < d_tree.numNodes());
2621 BSLS_ASSERT_SAFE(d_tree.firstNode() != d_tree.sentinel());
2622
2623 BloombergLP::bslalg::RbTreeUtil::deleteTree(&d_tree, &nodeFactory());
2624 }
2625#if defined(BSLS_ASSERT_SAFE_IS_USED)
2626 else {
2627 BSLS_ASSERT_SAFE(0 == d_tree.numNodes());
2628 BSLS_ASSERT_SAFE(d_tree.firstNode() == d_tree.sentinel());
2629 }
2630#endif
2631}
2632
2633// ACCESSORS
2634template <class KEY, class COMPARATOR, class ALLOCATOR>
2635inline
2638{
2639 return nodeFactory().allocator();
2640}
2641
2642template <class KEY, class COMPARATOR, class ALLOCATOR>
2643inline
2649
2650template <class KEY, class COMPARATOR, class ALLOCATOR>
2651inline
2657
2658template <class KEY, class COMPARATOR, class ALLOCATOR>
2659inline
2665
2666template <class KEY, class COMPARATOR, class ALLOCATOR>
2667inline
2673
2674template <class KEY, class COMPARATOR, class ALLOCATOR>
2675inline
2678{
2679 return const_iterator(d_tree.firstNode());
2680}
2681
2682template <class KEY, class COMPARATOR, class ALLOCATOR>
2683inline
2686{
2687 return const_iterator(d_tree.sentinel());
2688}
2689
2690template <class KEY, class COMPARATOR, class ALLOCATOR>
2691inline
2697
2698template <class KEY, class COMPARATOR, class ALLOCATOR>
2699inline
2705
2706template <class KEY, class COMPARATOR, class ALLOCATOR>
2707inline
2709{
2710 return find(key) != end();
2711}
2712
2713
2714// capacity:
2715template <class KEY, class COMPARATOR, class ALLOCATOR>
2716inline
2718{
2719 return 0 == d_tree.numNodes();
2720}
2721
2722template <class KEY, class COMPARATOR, class ALLOCATOR>
2723inline
2726{
2727 return d_tree.numNodes();
2728}
2729
2730
2731template <class KEY, class COMPARATOR, class ALLOCATOR>
2732inline
2735{
2736 return AllocatorTraits::max_size(get_allocator());
2737}
2738
2739template <class KEY, class COMPARATOR, class ALLOCATOR>
2740inline
2743{
2744 return comparator().keyComparator();
2745}
2746
2747template <class KEY, class COMPARATOR, class ALLOCATOR>
2748inline
2751{
2752 return value_compare(key_comp());
2753}
2754
2755} // close namespace bsl
2756
2757// FREE OPERATORS
2758template <class KEY, class COMPARATOR, class ALLOCATOR>
2759inline
2760bool bsl::operator==(const bsl::set<KEY, COMPARATOR, ALLOCATOR>& lhs,
2762{
2763 return BloombergLP::bslalg::RangeCompare::equal(lhs.begin(),
2764 lhs.end(),
2765 lhs.size(),
2766 rhs.begin(),
2767 rhs.end(),
2768 rhs.size());
2769}
2770
2771#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
2772template <class KEY, class COMPARATOR, class ALLOCATOR>
2773inline
2776{
2777 return !(lhs == rhs);
2778}
2779#endif
2780
2781#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
2782
2783template <class KEY, class COMPARATOR, class ALLOCATOR>
2784inline
2785BloombergLP::bslalg::SynthThreeWayUtil::Result<KEY>
2786bsl::operator<=>(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
2787 const set<KEY, COMPARATOR, ALLOCATOR>& rhs)
2788{
2789 return bsl::lexicographical_compare_three_way(
2790 lhs.begin(),
2791 lhs.end(),
2792 rhs.begin(),
2793 rhs.end(),
2794 BloombergLP::bslalg::SynthThreeWayUtil::compare);
2795}
2796
2797#else
2798
2799template <class KEY, class COMPARATOR, class ALLOCATOR>
2800inline
2803{
2804 return 0 > BloombergLP::bslalg::RangeCompare::lexicographical(lhs.begin(),
2805 lhs.end(),
2806 lhs.size(),
2807 rhs.begin(),
2808 rhs.end(),
2809 rhs.size());
2810}
2811
2812template <class KEY, class COMPARATOR, class ALLOCATOR>
2813inline
2816{
2817 return rhs < lhs;
2818}
2819
2820template <class KEY, class COMPARATOR, class ALLOCATOR>
2821inline
2824{
2825 return !(rhs < lhs);
2826}
2827
2828
2829template <class KEY, class COMPARATOR, class ALLOCATOR>
2830inline
2833{
2834 return !(lhs < rhs);
2835}
2836
2837#endif // BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
2838
2839// FREE FUNCTIONS
2840template <class KEY, class COMPARATOR, class ALLOCATOR, class PREDICATE>
2841inline
2843bsl::erase_if(set<KEY, COMPARATOR, ALLOCATOR>& s, PREDICATE predicate)
2844{
2845 return BloombergLP::bslstl::AlgorithmUtil::containerEraseIf(s, predicate);
2846}
2847
2848template <class KEY, class COMPARATOR, class ALLOCATOR>
2849inline
2854{
2855 a.swap(b);
2856}
2857
2858// ============================================================================
2859// TYPE TRAITS
2860// ============================================================================
2861
2862// Type traits for STL *ordered* containers:
2863//: o An ordered container defines STL iterators.
2864//: o An ordered container uses 'bslma' allocators if the (template parameter)
2865//: type 'ALLOCATOR' is convertible from 'bslma::Allocator*'.
2866
2867
2868
2869namespace bslalg {
2870
2871template <class KEY, class COMPARATOR, class ALLOCATOR>
2872struct HasStlIterators<bsl::set<KEY, COMPARATOR, ALLOCATOR> >
2874{};
2875
2876} // close namespace bslalg
2877
2878namespace bslma {
2879
2880template <class KEY, class COMPARATOR, class ALLOCATOR>
2881struct UsesBslmaAllocator<bsl::set<KEY, COMPARATOR, ALLOCATOR> >
2882 : bsl::is_convertible<Allocator*, ALLOCATOR>
2883{};
2884
2885} // close namespace bslma
2886
2887
2888
2889#endif // End C++11 code
2890
2891#endif
2892
2893// ----------------------------------------------------------------------------
2894// Copyright 2019 Bloomberg Finance L.P.
2895//
2896// Licensed under the Apache License, Version 2.0 (the "License");
2897// you may not use this file except in compliance with the License.
2898// You may obtain a copy of the License at
2899//
2900// http://www.apache.org/licenses/LICENSE-2.0
2901//
2902// Unless required by applicable law or agreed to in writing, software
2903// distributed under the License is distributed on an "AS IS" BASIS,
2904// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2905// See the License for the specific language governing permissions and
2906// limitations under the License.
2907// ----------------------------- END-OF-FILE ----------------------------------
2908
2909/** @} */
2910/** @} */
2911/** @} */
Definition ball_loggermanager.h:993
Definition bslma_bslallocator.h:580
Definition bslstl_pair.h:1210
Definition bslstl_set.h:657
pair< iterator, bool > insert(const value_type &value)
Definition bslstl_set.h:2326
bool empty() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2717
iterator lower_bound(const key_type &key)
Definition bslstl_set.h:1224
void swap(set &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(AllocatorTraits void clear() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:1179
set &operator=(BloombergLP::bslmf::MovableRef< set > rhs) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(AllocatorTraits iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2294
size_type erase(const key_type &key)
Definition bslstl_set.h:2560
const_iterator upper_bound(const key_type &key) const
Definition bslstl_set.h:1553
set(BloombergLP::bslmf::MovableRef< set > original)
Definition bslstl_set.h:2041
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, const_iterator >::type find(const LOOKUP_KEY &key) const
Definition bslstl_set.h:1465
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this set.
Definition bslstl_set.h:2725
iterator find(const key_type &key)
Definition bslstl_set.h:1191
const value_type & const_reference
Definition bslstl_set.h:750
const_reverse_iterator crbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2693
ALLOCATOR allocator_type
Definition bslstl_set.h:748
set & operator=(const set &rhs)
Definition bslstl_set.h:2235
value_type & reference
Definition bslstl_set.h:749
reverse_iterator rbegin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2310
KEY key_type
Definition bslstl_set.h:744
BloombergLP::bslstl::TreeIterator< const value_type, Node, difference_type > iterator
Definition bslstl_set.h:759
size_type max_size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2734
const_reverse_iterator crend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2701
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, const_iterator >::type upper_bound(const LOOKUP_KEY &key) const
Definition bslstl_set.h:1574
value_compare value_comp() const
Definition bslstl_set.h:2750
set(INPUT_ITERATOR first, INPUT_ITERATOR last, const ALLOCATOR &basicAllocator)
Definition bslstl_set.h:2153
AllocatorTraits::pointer pointer
Definition bslstl_set.h:754
AllocatorTraits::difference_type difference_type
Definition bslstl_set.h:753
AllocatorTraits::size_type size_type
Definition bslstl_set.h:752
set(const ALLOCATOR &basicAllocator)
Definition bslstl_set.h:2017
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, pair< iterator, iterator > >::type equal_range(const LOOKUP_KEY &key)
Definition bslstl_set.h:1328
set(const set &original, const typename type_identity< ALLOCATOR >::type &basicAllocator)
Definition bslstl_set.h:2052
reverse_iterator rend() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2318
~set()
Destroy this object.
Definition bslstl_set.h:2226
BloombergLP::bslstl::TreeIterator< const value_type, Node, difference_type > const_iterator
Definition bslstl_set.h:762
COMPARATOR key_compare
Definition bslstl_set.h:746
set(const set &original)
Definition bslstl_set.h:2025
key_compare key_comp() const
Definition bslstl_set.h:2742
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, iterator >::type lower_bound(const LOOKUP_KEY &key)
Definition bslstl_set.h:1245
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, iterator >::type find(const LOOKUP_KEY &key)
Definition bslstl_set.h:1208
pair< const_iterator, const_iterator > equal_range(const key_type &key) const
Definition bslstl_set.h:1592
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, size_type >::type count(const LOOKUP_KEY &key) const
Definition bslstl_set.h:1494
iterator erase(const_iterator first, const_iterator last)
Definition bslstl_set.h:2573
set(const COMPARATOR &comparator, const ALLOCATOR &basicAllocator=ALLOCATOR())
Definition bslstl_set.h:817
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2637
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2302
pair< iterator, iterator > equal_range(const key_type &key)
Definition bslstl_set.h:1298
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, iterator >::type upper_bound(const LOOKUP_KEY &key)
Definition bslstl_set.h:1280
const_iterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2677
bsl::reverse_iterator< const_iterator > const_reverse_iterator
Definition bslstl_set.h:764
bool contains(const key_type &key) const
Definition bslstl_set.h:2708
set()
Definition bslstl_set.h:2009
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, pair< const_iterator, const_iterator > >::type equal_range(const LOOKUP_KEY &key) const
Definition bslstl_set.h:1622
bsl::reverse_iterator< iterator > reverse_iterator
Definition bslstl_set.h:763
iterator upper_bound(const key_type &key)
Definition bslstl_set.h:1260
size_type count(const key_type &key) const
Definition bslstl_set.h:1476
AllocatorTraits::const_pointer const_pointer
Definition bslstl_set.h:755
COMPARATOR value_compare
Definition bslstl_set.h:747
set(INPUT_ITERATOR first, INPUT_ITERATOR last, const COMPARATOR &comparator=COMPARATOR(), const ALLOCATOR &basicAllocator=ALLOCATOR())
Definition bslstl_set.h:2097
iterator emplace_hint(const_iterator hint, Args &&... arguments)
Definition bslstl_set.h:2513
KEY value_type
Definition bslstl_set.h:745
set(BloombergLP::bslmf::MovableRef< set > original, const typename type_identity< ALLOCATOR >::type &basicAllocator)
Definition bslstl_set.h:2068
const_iterator lower_bound(const key_type &key) const
Definition bslstl_set.h:1516
bsl::enable_if< BloombergLP::bslmf::IsTransparentPredicate< COMPARATOR, LOOKUP_KEY >::value, const_iterator >::type lower_bound(const LOOKUP_KEY &key) const
Definition bslstl_set.h:1537
pair< iterator, bool > emplace(Args &&... arguments)
iterator erase(const_iterator position)
Definition bslstl_set.h:2544
const_iterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2685
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2018
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT_OPERATOR(...)
Definition bsls_keyword.h:635
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
#define BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(...)
Definition bsls_keyword.h:634
#define BSLS_PERFORMANCEHINT_PREDICT_LIKELY(expr)
Definition bsls_performancehint.h:451
#define BSLS_PERFORMANCEHINT_UNLIKELY_HINT
Definition bsls_performancehint.h:484
#define BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(expr)
Definition bsls_performancehint.h:452
Definition bdlb_printmethods.h:283
void swap(array< VALUE_TYPE, SIZE > &lhs, array< VALUE_TYPE, SIZE > &rhs)
T::const_iterator cend(const T &container)
Definition bslstl_iterator.h:1611
bool operator<(const array< VALUE_TYPE, SIZE > &lhs, const array< VALUE_TYPE, SIZE > &rhs)
T::const_reverse_iterator crbegin(const T &container)
Definition bslstl_iterator.h:1597
bool operator>(const array< VALUE_TYPE, SIZE > &lhs, const array< VALUE_TYPE, SIZE > &rhs)
bool operator>=(const array< VALUE_TYPE, SIZE > &lhs, const array< VALUE_TYPE, SIZE > &rhs)
bool operator<=(const array< VALUE_TYPE, SIZE > &lhs, const array< VALUE_TYPE, SIZE > &rhs)
deque< VALUE_TYPE, ALLOCATOR >::size_type erase(deque< VALUE_TYPE, ALLOCATOR > &deq, const BDE_OTHER_TYPE &value)
Definition bslstl_deque.h:4126
T::iterator begin(T &container)
Definition bslstl_iterator.h:1495
T::const_iterator cbegin(const T &container)
Definition bslstl_iterator.h:1553
T::iterator end(T &container)
Definition bslstl_iterator.h:1523
deque< VALUE_TYPE, ALLOCATOR >::size_type erase_if(deque< VALUE_TYPE, ALLOCATOR > &deq, PREDICATE predicate)
Definition bslstl_deque.h:4135
bool operator!=(const memory_resource &a, const memory_resource &b)
T::const_reverse_iterator crend(const T &container)
Definition bslstl_iterator.h:1654
Definition bdlc_flathashmap.h:1805
Definition balxml_encoderoptions.h:68
Definition bdlbb_blob.h:576
Definition bslma_allocatortraits.h:1061
BloombergLP::bslma::AllocatorTraits_ConstPointerType< ALLOCATOR >::type const_pointer
Definition bslma_allocatortraits.h:1152
BloombergLP::bslma::AllocatorTraits_SizeType< ALLOCATOR >::type size_type
Definition bslma_allocatortraits.h:1165
BloombergLP::bslma::AllocatorTraits_PointerType< ALLOCATOR >::type pointer
Definition bslma_allocatortraits.h:1149
BloombergLP::bslma::AllocatorTraits_DifferenceType< ALLOCATOR >::type difference_type
Definition bslma_allocatortraits.h:1162
Definition bslmf_enableif.h:525
Definition bslmf_isconvertible.h:867
t_TYPE type
Definition bslmf_typeidentity.h:216
Definition bslalg_hasstliterators.h:99
Definition bslma_usesbslmaallocator.h:343