BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_set_cpp03.h
Go to the documentation of this file.
1/// @file bslstl_set_cpp03.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_set_cpp03.h -*-C++-*-
8
9// Automatically generated file. **DO NOT EDIT**
10
11#ifndef INCLUDED_BSLSTL_SET_CPP03
12#define INCLUDED_BSLSTL_SET_CPP03
13
14/// @defgroup bslstl_set_cpp03 bslstl_set_cpp03
15/// @brief Provide C++03 implementation for bslstl_set.h
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_set_cpp03
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_set_cpp03-purpose"> Purpose</a>
25/// * <a href="#bslstl_set_cpp03-classes"> Classes </a>
26/// * <a href="#bslstl_set_cpp03-description"> Description </a>
27///
28/// # Purpose {#bslstl_set_cpp03-purpose}
29/// Provide C++03 implementation for bslstl_set.h
30///
31/// # Classes {#bslstl_set_cpp03-classes}
32/// See bslstl_set.h for list of classes
33///
34/// @see bslstl_set
35///
36/// # Description {#bslstl_set_cpp03-description}
37/// This component is the C++03 translation of a C++11 component,
38/// generated by the 'sim_cpp11_features.pl' program. If the original header
39/// contains any specially delimited regions of C++11 code, then this generated
40/// file contains the C++03 equivalent, i.e., with variadic templates expanded
41/// and rvalue-references replaced by 'bslmf::MovableRef' objects. The header
42/// code in this file is designed to be '#include'd into the original header
43/// when compiling with a C++03 compiler. If there are no specially delimited
44/// regions of C++11 code, then this header contains no code and is not
45/// '#include'd in the original header.
46///
47/// Generated on Thu Mar 19 20:53:55 2026
48/// Command line: sim_cpp11_features.pl bslstl_set.h
49/// @}
50/** @} */
51/** @} */
52
53/** @addtogroup bsl
54 * @{
55 */
56/** @addtogroup bslstl
57 * @{
58 */
59/** @addtogroup bslstl_set_cpp03
60 * @{
61 */
62
63#ifdef COMPILING_BSLSTL_SET_H
64
65namespace bsl {
66
67 // =========
68 // class set
69 // =========
70
71/// This class template implements a value-semantic container type holding
72/// an ordered sequence of unique keys (of the template parameter type,
73/// `KEY`).
74///
75/// This class:
76/// * supports a complete set of *value-semantic* operations
77/// except for `BDEX` serialization
78/// * is *exception-neutral* (agnostic except for the `at` method)
79/// * is *alias-safe*
80/// * is `const` *thread-safe*
81/// For terminology see @ref bsldoc_glossary .
82///
83/// See @ref bslstl_set_cpp03
84template <class KEY,
85 class COMPARATOR = std::less<KEY>,
86 class ALLOCATOR = allocator<KEY> >
87class set {
88
89 // PRIVATE TYPES
90
91 /// This typedef is an alias for the type of key objects maintained by
92 /// this set.
93 typedef const KEY ValueType;
94
95 /// This typedef is an alias for the comparator used internally by this
96 /// set.
97 typedef BloombergLP::bslstl::SetComparator<KEY, COMPARATOR> Comparator;
98
99 /// This typedef is an alias for the type of nodes held by the tree (of
100 /// nodes) used to implement this set.
101 typedef BloombergLP::bslstl::TreeNode<KEY> Node;
102
103 /// This typedef is an alias for the factory type used to create and
104 /// destroy `Node` objects.
105 typedef BloombergLP::bslstl::TreeNodePool<KEY, ALLOCATOR> NodeFactory;
106
107 /// This typedef is an alias for the allocator traits type associated
108 /// with this container.
109 typedef bsl::allocator_traits<ALLOCATOR> AllocatorTraits;
110
111 /// This typedef is a convenient alias for the utility associated with
112 /// movable references.
113 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
114
115 /// This class is a wrapper around the comparator and allocator data
116 /// members. It takes advantage of the empty-base optimization (EBO) so
117 /// that if the comparator is stateless, it takes up no space.
118 ///
119 /// TBD: This struct should eventually be replaced by the use of a
120 /// general EBO-enabled component that provides a `pair`-like interface
121 /// or a `tuple`.
122 ///
123 /// See @ref bslstl_set_cpp03
124 class DataWrapper : public Comparator {
125
126 // DATA
127 NodeFactory d_pool; // pool of 'Node' objects
128
129 private:
130 // NOT IMPLEMENTED
131 DataWrapper(const DataWrapper&);
132 DataWrapper& operator=(const DataWrapper&);
133
134 public:
135 // CREATORS
136
137 /// Create a data wrapper using a copy of the specified `comparator`
138 /// to order keys and a copy of the specified `basicAllocator` to
139 /// supply memory.
140 explicit DataWrapper(const COMPARATOR& comparator,
141 const ALLOCATOR& basicAllocator);
142
143 /// Create a data wrapper initialized to the contents of the `pool`
144 /// associated with the specified `original` data wrapper. The
145 /// comparator and allocator associated with `original` are
146 /// propagated to the new data wrapper. `original` is left in a
147 /// valid but unspecified state.
148 DataWrapper(
149 BloombergLP::bslmf::MovableRef<DataWrapper> original);// IMPLICIT
150
151 // MANIPULATORS
152
153 /// Return a reference providing modifiable access to the node
154 /// factory associated with this data wrapper.
155 NodeFactory& nodeFactory();
156
157 // ACCESSORS
158
159 /// Return a reference providing non-modifiable access to the node
160 /// factory associated with this data wrapper.
161 const NodeFactory& nodeFactory() const;
162 };
163
164 // DATA
165 DataWrapper d_compAndAlloc;
166 // comparator and pool of `Node`
167 // objects
168
169 BloombergLP::bslalg::RbTreeAnchor d_tree; // balanced tree of `Node`
170 // objects
171
172 public:
173 // PUBLIC TYPES
174 typedef KEY key_type;
175 typedef KEY value_type;
176 typedef COMPARATOR key_compare;
177 typedef COMPARATOR value_compare;
178 typedef ALLOCATOR allocator_type;
179 typedef value_type& reference;
180 typedef const value_type& const_reference;
181
182 typedef typename AllocatorTraits::size_type size_type;
184 typedef typename AllocatorTraits::pointer pointer;
186
187 typedef BloombergLP::bslstl::TreeIterator<const value_type,
188 Node,
190 typedef BloombergLP::bslstl::TreeIterator<const value_type,
191 Node,
193 typedef bsl::reverse_iterator<iterator> reverse_iterator;
194 typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
195
196 private:
197 // PRIVATE MANIPULATORS
198
199 /// Return a reference providing modifiable access to the node-allocator
200 /// for this tree.
201 NodeFactory& nodeFactory();
202
203 /// Return a reference providing modifiable access to the comparator for
204 /// this tree.
205 Comparator& comparator();
206
207 /// Efficiently exchange the value, comparator, and allocator of this
208 /// object with the value, comparator, and allocator of the specified
209 /// `other` object. This method provides the no-throw exception-safety
210 /// guarantee, *unless* swapping the (user-supplied) comparator or
211 /// allocator objects can throw.
212 void quickSwapExchangeAllocators(set& other);
213
214 /// Efficiently exchange the value and comparator of this object with
215 /// the value and comparator of the specified `other` object. This
216 /// method provides the no-throw exception-safety guarantee, *unless*
217 /// swapping the (user-supplied) comparator objects can throw.
218 ///
219 /// \pre The behavior is undefined unless this object was created with the same
220 /// allocator as `other`.
221 void quickSwapRetainAllocators(set& other);
222
223 /// Insert the values between the specified `first` and `last` into an
224 /// initially empty set. If sorted, directly place each value in its
225 /// proper position. If an out of order value is detected, revert to
226 /// normal insertion.
227 template <class INPUT_ITERATOR, class SENTINEL>
228 void constructFromRange(INPUT_ITERATOR first, SENTINEL last);
229
230#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
231 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
232
233 /// Insert the values between the specified `first` and `last` into an
234 /// initially empty set. The specified 'numElements` is used to improve
235 /// performance. If sorted, directly place each value in its proper
236 /// position. If an out of order value is detected, revert to normal insertion.
237 ///
238 /// \pre The behavior is undefined if the iterators support
239 /// the calculation of distance and `numElements` is not the distance
240 /// from `first` to `last`.
241 template <class INPUT_ITERATOR, class SENTINEL>
242 void constructFromRange(INPUT_ITERATOR first,
243 SENTINEL last,
244 size_t numElements);
245#endif
246
247 // Insert the values between `first` and `last` into this map.
248 template <class INPUT_ITERATOR, class SENTINEL>
249 void insertFromRange(INPUT_ITERATOR first,
250 SENTINEL last);
251
252#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
253 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
254
255 /// Insert the values between the specified `first` and `last` into this
256 /// map. The specified `numElements` is used to improve performance.
257 ///
258 /// \pre The behavior is undefined if the iterators support the calculation
259 /// of distance and `numElements` is not the distance from `first` to
260 /// `last`.
261 template <class INPUT_ITERATOR, class SENTINEL>
262 void insertFromRange(INPUT_ITERATOR first,
263 SENTINEL last,
264 size_t numElements);
265#endif
266
267 // PRIVATE ACCESSORS
268
269 /// Return a reference providing non-modifiable access to the
270 /// node-allocator for this tree.
271 const NodeFactory& nodeFactory() const;
272
273 /// Return a reference providing non-modifiable access to the comparator
274 /// for this tree.
275 const Comparator& comparator() const;
276
277 public:
278 // CREATORS
279
280 /// Create an empty set. Optionally specify a `comparator` used to
281 /// order keys contained in this object. If `comparator` is not
282 /// supplied, a default-constructed object of the (template parameter)
283 /// type `COMPARATOR` is used. Optionally specify a `basicAllocator`
284 /// used to supply memory. If `basicAllocator` is not supplied, a
285 /// default-constructed object of the (template parameter) type
286 /// `ALLOCATOR` is used. If the type `ALLOCATOR` is `bsl::allocator`
287 /// and `basicAllocator` is not supplied, the currently installed default allocator is used.
288 ///
289 /// \note Note that a `bslma::Allocator *` can be
290 /// supplied for `basicAllocator` if the type `ALLOCATOR` is
291 /// `bsl::allocator` (the default).
292 set();
293 explicit set(const COMPARATOR& comparator,
294 const ALLOCATOR& basicAllocator = ALLOCATOR())
295 : d_compAndAlloc(comparator, basicAllocator)
296 , d_tree()
297 {
298 // The implementation is placed here in the class definition to work
299 // around an AIX compiler bug, where the constructor can fail to
300 // compile because it is unable to find the definition of the default
301 // argument. This occurs when a templatized class wraps around the
302 // container and the comparator is defined after the new class.
303 }
304
305 /// Create an empty set that uses the specified `basicAllocator` to
306 /// supply memory. Use a default-constructed object of the (template
307 /// parameter) type `COMPARATOR` to order the keys contained in this set.
308 ///
309 /// \note Note that a `bslma::Allocator *` can be supplied for
310 /// `basicAllocator` if the (template parameter) type `ALLOCATOR` is
311 /// `bsl::allocator` (the default).
312 explicit set(const ALLOCATOR& basicAllocator);
313
314 /// Create a set having the same value as the specified `original`
315 /// object. Use a copy of `original.key_comp()` to order the keys
316 /// contained in this set. Use the allocator returned by
317 /// `bsl::allocator_traits<ALLOCATOR>::
318 /// select_on_container_copy_construction(original.get_allocator())` to
319 /// allocate memory. This method requires that the (template parameter)
320 /// type `KEY` be `copy-insertable` into this set (see {Requirements on
321 /// `KEY`}).
322 set(const set& original);
323
324 /// Create a set having the same value as the specified `original`
325 /// object by moving (in constant time) the contents of `original` to
326 /// the new set. Use a copy of `original.key_comp()` to order the keys
327 /// contained in this set. The allocator associated with `original` is
328 /// propagated for use in the newly-created set. `original` is left in
329 /// a valid but unspecified state.
330 set(BloombergLP::bslmf::MovableRef<set> original); // IMPLICIT
331
332 /// Create a set having the same value as the specified `original`
333 /// object that uses the specified `basicAllocator` to supply memory.
334 /// Use a copy of `original.key_comp()` to order the keys contained in
335 /// this set. This method requires that the (template parameter) type
336 /// `KEY` be `copy-insertable` into this set (see {Requirements on `KEY`}).
337 ///
338 /// \note Note that a `bslma::Allocator *` can be supplied for
339 /// `basicAllocator` if the (template parameter) type `ALLOCATOR` is
340 /// `bsl::allocator` (the default).
341 set(const set& original,
342 const typename type_identity<ALLOCATOR>::type& basicAllocator);
343
344 /// Create a set having the same value as the specified `original`
345 /// object that uses the specified `basicAllocator` to supply memory.
346 /// The contents of `original` are moved (in constant time) to the new
347 /// set if `basicAllocator == original.get_allocator()`, and are move-
348 /// inserted (in linear time) using `basicAllocator` otherwise.
349 /// `original` is left in a valid but unspecified state. Use a copy of
350 /// `original.key_comp()` to order the keys contained in this set. This
351 /// method requires that the (template parameter) type `KEY` be
352 /// `move-insertable` into this set (see {Requirements on `KEY`}).
353 ///
354 /// \note Note that a `bslma::Allocator *` can be supplied for `basicAllocator` if
355 /// the (template parameter) type `ALLOCATOR` is `bsl::allocator` (the
356 /// default).
357 set(BloombergLP::bslmf::MovableRef<set> original,
358 const typename type_identity<ALLOCATOR>::type& basicAllocator);
359
360 /// Create a set, and insert each `value_type` object in the sequence
361 /// starting at the specified `first` element, and ending immediately
362 /// before the specified `last` element, ignoring those keys having a
363 /// value equivalent to that which appears earlier in the sequence.
364 /// Optionally specify a `comparator` used to order keys contained in
365 /// this object. If `comparator` is not supplied, a default-constructed
366 /// object of the (template parameter) type `COMPARATOR` is used.
367 /// Optionally specify a `basicAllocator` used to supply memory. If
368 /// `basicAllocator` is not supplied, a default-constructed object of
369 /// the (template parameter) type `ALLOCATOR` is used. If the type
370 /// `ALLOCATOR` is `bsl::allocator` and `basicAllocator` is not
371 /// supplied, the currently installed default allocator is used. If the
372 /// sequence `first` to `last` is ordered according to `comparator`,
373 /// then this operation has `O[N]` complexity, where `N` is the number
374 /// of elements between `first` and `last`, otherwise this operation has
375 /// `O[N * log(N)]` complexity. The (template parameter) type
376 /// `INPUT_ITERATOR` shall meet the requirements of an input iterator
377 /// defined in the C++11 standard [24.2.3] providing access to values of
378 /// a type convertible to `value_type`, and `value_type` must be
379 /// `emplace-constructible` from `*i` into this set, where `i` is a
380 /// dereferenceable iterator in the range `[first .. last)` (see {Requirements on `KEY`}).
381 ///
382 /// \pre The behavior is undefined unless `first`
383 /// and `last` refer to a sequence of valid values where `first` is at a position at or before `last`.
384 ///
385 /// \note Note that a `bslma::Allocator *` can
386 /// be supplied for `basicAllocator` if the type `ALLOCATOR` is
387 /// `bsl::allocator` (the default).
388 template <class INPUT_ITERATOR>
389 set(INPUT_ITERATOR first,
390 INPUT_ITERATOR last,
391 const COMPARATOR& comparator = COMPARATOR(),
392 const ALLOCATOR& basicAllocator = ALLOCATOR());
393 template <class INPUT_ITERATOR>
394 set(INPUT_ITERATOR first,
395 INPUT_ITERATOR last,
396 const ALLOCATOR& basicAllocator);
397
398 /// Create a set having the (`value_type`) values obtained from the
399 /// specified `range`. Ignore those those objects having a key equivalent
400 /// to that which appears earlier in the sequence. Optionally specify a
401 /// `comparator` used to order key-value pairs contained in this object.
402 /// If `comparator` is not supplied, a default-constructed object of the
403 /// (template parameter) type `COMPARATOR` is used. Optionally specify a
404 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
405 /// supplied, a default-constructed object of the (template parameter) type
406 /// `ALLOCATOR` is used. If the type `ALLOCATOR` is `bsl::allocator`
407 /// (the default), then `basicAllocator`, if supplied, shall be
408 /// convertible to `bslma::Allocator *`. If the type `ALLOCATOR` is
409 /// `bsl::allocator` and `basicAllocator` is not supplied, the currently
410 /// installed default allocator is used. If values obtained from `range
411 /// are ordered according to `comparator`, then this operation has `O[N]`
412 /// complexity, where `N` is the number of values in the `range`;
413 /// otherwise, this operation has `O[N * log(N)]` complexity.
414 ///
415 /// \note Note that `RANGE` must meet the requirements of an input range and the values
416 /// from `range` must have a type matching or convertible to `value_type`.
417 template <class RANGE>
421 const COMPARATOR& comparator = COMPARATOR(),
422 const ALLOCATOR& basicAllocator = ALLOCATOR())
423 : d_compAndAlloc(comparator, basicAllocator)
424 , d_tree()
425 {
426 // Defined inline to avoid Windows errors.
427
428#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
429 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
430 if constexpr (ranges::sized_range<RANGE>) {
431 constructFromRange(bsl::ranges::begin(range),
432 bsl::ranges::end (range),
433 bsl::ranges::size (range));
434 } else // ...
435#endif
436 {
437 constructFromRange(bsl::ranges::begin(range),
438 bsl::ranges::end (range));
439 }
440 }
441
442 template <class RANGE>
444 set(from_range_t ,
446 const ALLOCATOR& basicAllocator)
447 : d_compAndAlloc(COMPARATOR(), basicAllocator)
448 , d_tree()
449 {
450 // Defined inline to avoid Windows errors.
451
452 set other(bsl::from_range,
453 range,
454 COMPARATOR(),
455 nodeFactory().allocator());
456 quickSwapRetainAllocators(other);
457 }
458
459#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
460 /// Create a set and insert each `value_type` object in the specified
461 /// `values` initializer list, ignoring those keys having a value
462 /// equivalent to that which appears earlier in the list. Optionally
463 /// specify a `comparator` used to order keys contained in this object.
464 /// If `comparator` is not supplied, a default-constructed object of the
465 /// (template parameter) type `COMPARATOR` is used. Optionally specify
466 /// a `basicAllocator` used to supply memory. If `basicAllocator` is
467 /// not supplied, a default-constructed object of the (template
468 /// parameter) type `ALLOCATOR` is used. If the type `ALLOCATOR` is
469 /// `bsl::allocator` and `basicAllocator` is not supplied, the currently
470 /// installed default allocator is used. If `values` is ordered
471 /// according to `comparator`, then this operation has `O[N]`
472 /// complexity, where `N` is the number of elements in `list`; otherwise
473 /// this operation has `O[N * log(N)]` complexity. This method requires
474 /// that the (template parameter) type `KEY` be `copy-insertable` into this set (see {Requirements on `KEY`}).
475 ///
476 /// \note Note that a
477 /// `bslma::Allocator *` can be supplied for `basicAllocator` if the
478 /// type `ALLOCATOR` is `bsl::allocator` (the default).
479 set(std::initializer_list<KEY> values,
480 const COMPARATOR& comparator = COMPARATOR(),
481 const ALLOCATOR& basicAllocator = ALLOCATOR());
482 set(std::initializer_list<KEY> values,
483 const ALLOCATOR& basicAllocator);
484#endif
485
486 /// Destroy this object.
487 ~set();
488
489 // MANIPULATORS
490
491 /// Assign to this object the value and comparator of the specified
492 /// `rhs` object, propagate to this object the allocator of `rhs` if the
493 /// `ALLOCATOR` type has trait @ref propagate_on_container_copy_assignment ,
494 /// and return a reference providing modifiable access to this object.
495 /// If an exception is thrown, `*this` is left in a valid but
496 /// unspecified state. This method requires that the (template
497 /// parameter) type `KEY` be `copy-assignable` and `copy-insertable`
498 /// into this set (see {Requirements on `KEY`}).
499 set& operator=(const set& rhs);
500
501 /// Assign to this object the value and comparator of the specified
502 /// `rhs` object, propagate to this object the allocator of `rhs` if the
503 /// `ALLOCATOR` type has trait @ref propagate_on_container_move_assignment ,
504 /// and return a reference providing modifiable access to this object.
505 /// The contents of `rhs` are moved (in constant time) to this set if
506 /// `get_allocator() == rhs.get_allocator()` (after accounting for the
507 /// aforementioned trait); otherwise, all elements in this set are
508 /// either destroyed or move-assigned to and each additional element in
509 /// `rhs` is move-inserted into this set. `rhs` is left in a valid but
510 /// unspecified state, and if an exception is thrown, `*this` is left
511 /// in a valid but unspecified state. This method requires that the
512 /// (template parameter) type `KEY` be `move-assignable` and
513 /// `move-insertable` into this set (see {Requirements on `KEY`}).
514 set& operator=(BloombergLP::bslmf::MovableRef<set> rhs)
516 AllocatorTraits::is_always_equal::value
517 && std::is_nothrow_move_assignable<COMPARATOR>::value);
518
519#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
520 /// Assign to this object the value resulting from first clearing this
521 /// set and then inserting each `value_type` object in the specified
522 /// `values` initializer list, ignoring those keys having a value
523 /// equivalent to that which appears earlier in the list; return a
524 /// reference providing modifiable access to this object. This method
525 /// requires that the (template parameter) type `KEY` be
526 /// `copy-insertable` into this set (see {Requirements on `KEY`}).
527 set& operator=(std::initializer_list<KEY> values);
528#endif
529
530 /// Return an iterator providing modifiable access to the first
531 /// `value_type` object in the ordered sequence of `value_type` objects
532 /// maintained by this set, or the `end` iterator if this set is empty.
534
535 /// Return an iterator providing modifiable access to the past-the-end
536 /// element in the ordered sequence of `value_type` objects maintained
537 /// by this set.
539
540 /// Return a reverse iterator providing modifiable access to the last
541 /// `value_type` object in the ordered sequence of `value_type` objects
542 /// maintained by this set, or `rend` if this object is empty.
544
545 /// Return a reverse iterator providing modifiable access to the
546 /// prior-to-the-beginning element in the ordered sequence of
547 /// `value_type` objects maintained by this set.
549
550 /// Insert the specified `value` into this set if a key equivalent to
551 /// `value` does not already exist in this set; otherwise, if a key
552 /// equivalent to `value` already exists in this set, this method has no
553 /// effect. Return a pair whose `first` member is an iterator referring
554 /// to the (possibly newly inserted) `value_type` object in this set
555 /// that is equivalent to `value`, and whose `second` member is `true`
556 /// if a new value was inserted, and `false` if the key was already
557 /// present. This method requires that the (template parameter) type
558 /// `KEY` be `copy-insertable` into this set (see {Requirements on
559 /// `KEY`}).
560 pair<iterator, bool> insert(const value_type& value);
561
562 /// Insert the specified `value` into this set if a key equivalent to
563 /// `value` does not already exist in this set; otherwise, if a key
564 /// equivalent to `value` already exists in this set, this method has no
565 /// effect. `value` is left in a valid but unspecified state. Return a
566 /// pair whose `first` member is an iterator referring to the (possibly
567 /// newly inserted) `value_type` object in this set that is equivalent
568 /// to `value`, and whose `second` member is `true` if a new value was
569 /// inserted, and `false` if the key was already present. This method
570 /// requires that the (template parameter) type `KEY` be
571 /// `move-insertable` (see {Requirements on `KEY`}).
572 pair<iterator, bool> insert(
573 BloombergLP::bslmf::MovableRef<value_type> value);
574
575// {{{ BEGIN GENERATED CODE
576// The generated code below is a workaround for the absence of perfect
577// forwarding in some compilers.
578 template <class LOOKUP_KEY>
579 typename enable_if<
580 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
581 LOOKUP_KEY>::value
582 , pair<iterator, bool> >::type
584 {
585 typedef pair<iterator, bool> Result;
586
587 int comparisonResult;
588 BloombergLP::bslalg::RbTreeNode *insertLocation =
589 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
590 &comparisonResult,
591 &d_tree,
592 this->comparator(),
593 value);
594 if (!comparisonResult) {
595 return Result(iterator(insertLocation), false);
596 }
597 BloombergLP::bslalg::RbTreeNode *node =
598 nodeFactory().emplaceIntoNewNode(
599 BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, value));
600 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
601 insertLocation,
602 comparisonResult < 0,
603 node);
604 return Result(iterator(node), true);
605 }
606// }}} END GENERATED CODE
607
608 /// Insert the specified `value` into this set (in amortized constant
609 /// time if the specified `hint` is a valid immediate successor to
610 /// `value`), if a key equivalent to `value` does not already exist in
611 /// this set; otherwise, if a key equivalent to `value` already exists
612 /// in this set, this method has no effect. Return an iterator
613 /// referring to the (possibly newly inserted) `value_type` object in
614 /// this set that is equivalent to `value`. If `hint` is not a valid
615 /// immediate successor to `value`, this operation has `O[log(N)]`
616 /// complexity, where `N` is the size of this set. This method requires
617 /// that the (template parameter) type `KEY` be `copy-insertable` into
618 /// this set (see {Requirements on `KEY`}).
619 ///
620 /// \pre The behavior is undefined unless `hint` is an iterator in the range `[begin() .. end()]` (both
621 /// endpoints included).
622 iterator insert(const_iterator hint, const value_type& value);
623
624 /// Insert the specified `value` into this set (in amortized constant
625 /// time if the specified `hint` is a valid immediate successor to
626 /// `value`) if a key equivalent to `value` does not already exist in
627 /// this set; otherwise, this method has no effect. `value` is left in
628 /// a valid but unspecified state. Return an iterator referring to the
629 /// (possibly newly inserted) `value_type` object in this set that is
630 /// equivalent to `value`. If `hint` is not a valid immediate successor
631 /// to `value`, this operation has `O[log(N)]` complexity, where `N` is
632 /// the size of this set. This method requires that the (template
633 /// parameter) type `KEY` be `move-insertable` (see {Requirements on `KEY`}).
634 ///
635 /// \pre The behavior is undefined unless `hint` is an iterator in
636 /// the range `[begin() .. end()]` (both endpoints included).
638 BloombergLP::bslmf::MovableRef<value_type> value);
639
640// {{{ BEGIN GENERATED CODE
641// The generated code below is a workaround for the absence of perfect
642// forwarding in some compilers.
643 template <class LOOKUP_KEY>
644 typename enable_if<
645 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
646 LOOKUP_KEY>::value
648 iterator>::value
650 const_iterator>::value
651 , iterator>::type
653 BSLS_COMPILERFEATURES_FORWARD_REF(LOOKUP_KEY) value)
654 {
655 BloombergLP::bslalg::RbTreeNode *hintNode =
656 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
657
658 int comparisonResult;
659 BloombergLP::bslalg::RbTreeNode *insertLocation =
660 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
661 &comparisonResult,
662 &d_tree,
663 this->comparator(),
664 value,
665 hintNode);
666 if (!comparisonResult) {
667 return iterator(insertLocation);
668 }
669
670 BloombergLP::bslalg::RbTreeNode *node =
671 nodeFactory().emplaceIntoNewNode(
672 BSLS_COMPILERFEATURES_FORWARD(LOOKUP_KEY, value));
673
674 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
675 insertLocation,
676 comparisonResult < 0,
677 node);
678 return iterator(node);
679 }
680// }}} END GENERATED CODE
681
682 /// Insert into this set the value of each `value_type` object in the
683 /// range starting at the specified `first` iterator and ending
684 /// immediately before the specified `last` iterator, if a key
685 /// equivalent to the object is not already contained in this set. The
686 /// (template parameter) type `INPUT_ITERATOR` shall meet the
687 /// requirements of an input iterator defined in the C++11 standard
688 /// [24.2.3] providing access to values of a type convertible to
689 /// `value_type`, and `value_type` must be `emplace-constructible` from
690 /// `*i` into this set, where `i` is a dereferenceable iterator in the
691 /// range `[first .. last)` (see {Requirements on `KEY`}).
692 ///
693 /// \pre The behavior is undefined unless `first` and `last` refer to a sequence of valid
694 /// values where `first` is at a position at or before `last`.
695 template <class INPUT_ITERATOR>
696 void insert(INPUT_ITERATOR first, INPUT_ITERATOR last);
697
698#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
699 /// Insert into this set the value of each `value_type` object in the
700 /// specified `values` initializer list if a key equivalent to the
701 /// object is not already contained in this set. This method requires
702 /// that the (template parameter) type `KEY` be `copy-insertable` (see
703 /// {Requirements on `KEY`}).
704 void insert(std::initializer_list<KEY> values);
705#endif
706
707 /// Insert into this set the value of each `value_type` object in the
708 /// specified `range` if the key equivalent of that object is not
709 /// already contained in this map. The (template parameter) type `RANGE`
710 /// must meet the requirements the C++20 standard [ranges] providing access
711 /// to values of a type convertible to `value_type`, and `value_type` must
712 /// be `emplace-constructible` from `*i` into this map, where `i` is a
713 /// dereferenceable iterator obtained from `range` (see {Requirements on `KEY`}).
714 ///
715 /// \pre The behavior is undefined if `range` overlaps this set.
716 template <class RANGE>
719 {
720 // Defined inline to avoid Windows errors.
721
722#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
723 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
724 if constexpr (ranges::sized_range<RANGE>) {
725 insertFromRange(bsl::ranges::begin(range),
726 bsl::ranges::end (range),
727 bsl::ranges::size (range));
728 } else // ...
729#endif
730 {
731 insertFromRange(bsl::ranges::begin(range),
732 bsl::ranges::end (range));
733 }
734 }
735
736#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
737// {{{ BEGIN GENERATED CODE
738// Command line: sim_cpp11_features.pl bslstl_set.h
739#ifndef BSLSTL_SET_VARIADIC_LIMIT
740#define BSLSTL_SET_VARIADIC_LIMIT 10
741#endif
742#ifndef BSLSTL_SET_VARIADIC_LIMIT_C
743#define BSLSTL_SET_VARIADIC_LIMIT_C BSLSTL_SET_VARIADIC_LIMIT
744#endif
745
746#if BSLSTL_SET_VARIADIC_LIMIT_C >= 0
747 pair<iterator, bool> emplace(
748 );
749#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 0
750
751#if BSLSTL_SET_VARIADIC_LIMIT_C >= 1
752 template <class Args_01>
753 pair<iterator, bool> emplace(
754 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01);
755#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 1
756
757#if BSLSTL_SET_VARIADIC_LIMIT_C >= 2
758 template <class Args_01,
759 class Args_02>
760 pair<iterator, bool> emplace(
761 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
762 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02);
763#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 2
764
765#if BSLSTL_SET_VARIADIC_LIMIT_C >= 3
766 template <class Args_01,
767 class Args_02,
768 class Args_03>
769 pair<iterator, bool> emplace(
770 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
771 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
772 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03);
773#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 3
774
775#if BSLSTL_SET_VARIADIC_LIMIT_C >= 4
776 template <class Args_01,
777 class Args_02,
778 class Args_03,
779 class Args_04>
780 pair<iterator, bool> emplace(
781 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
782 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
783 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
784 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04);
785#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 4
786
787#if BSLSTL_SET_VARIADIC_LIMIT_C >= 5
788 template <class Args_01,
789 class Args_02,
790 class Args_03,
791 class Args_04,
792 class Args_05>
793 pair<iterator, bool> emplace(
794 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
795 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
796 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
797 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
798 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05);
799#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 5
800
801#if BSLSTL_SET_VARIADIC_LIMIT_C >= 6
802 template <class Args_01,
803 class Args_02,
804 class Args_03,
805 class Args_04,
806 class Args_05,
807 class Args_06>
808 pair<iterator, bool> emplace(
809 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
810 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
811 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
812 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
813 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
814 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06);
815#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 6
816
817#if BSLSTL_SET_VARIADIC_LIMIT_C >= 7
818 template <class Args_01,
819 class Args_02,
820 class Args_03,
821 class Args_04,
822 class Args_05,
823 class Args_06,
824 class Args_07>
825 pair<iterator, bool> emplace(
826 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
827 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
828 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
829 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
830 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
831 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
832 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07);
833#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 7
834
835#if BSLSTL_SET_VARIADIC_LIMIT_C >= 8
836 template <class Args_01,
837 class Args_02,
838 class Args_03,
839 class Args_04,
840 class Args_05,
841 class Args_06,
842 class Args_07,
843 class Args_08>
844 pair<iterator, bool> emplace(
845 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
846 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
847 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
848 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
849 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
850 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
851 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
852 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08);
853#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 8
854
855#if BSLSTL_SET_VARIADIC_LIMIT_C >= 9
856 template <class Args_01,
857 class Args_02,
858 class Args_03,
859 class Args_04,
860 class Args_05,
861 class Args_06,
862 class Args_07,
863 class Args_08,
864 class Args_09>
865 pair<iterator, bool> emplace(
866 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
867 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
868 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
869 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
870 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
871 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
872 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
873 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
874 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09);
875#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 9
876
877#if BSLSTL_SET_VARIADIC_LIMIT_C >= 10
878 template <class Args_01,
879 class Args_02,
880 class Args_03,
881 class Args_04,
882 class Args_05,
883 class Args_06,
884 class Args_07,
885 class Args_08,
886 class Args_09,
887 class Args_10>
888 pair<iterator, bool> emplace(
889 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
890 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
891 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
892 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
893 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
894 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
895 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
896 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
897 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
898 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10);
899#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 10
900
901
902#if BSLSTL_SET_VARIADIC_LIMIT_C >= 0
904#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 0
905
906#if BSLSTL_SET_VARIADIC_LIMIT_C >= 1
907 template <class Args_01>
909 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01);
910#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 1
911
912#if BSLSTL_SET_VARIADIC_LIMIT_C >= 2
913 template <class Args_01,
914 class Args_02>
916 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
917 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02);
918#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 2
919
920#if BSLSTL_SET_VARIADIC_LIMIT_C >= 3
921 template <class Args_01,
922 class Args_02,
923 class Args_03>
925 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
926 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
927 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03);
928#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 3
929
930#if BSLSTL_SET_VARIADIC_LIMIT_C >= 4
931 template <class Args_01,
932 class Args_02,
933 class Args_03,
934 class Args_04>
936 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
937 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
938 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
939 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04);
940#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 4
941
942#if BSLSTL_SET_VARIADIC_LIMIT_C >= 5
943 template <class Args_01,
944 class Args_02,
945 class Args_03,
946 class Args_04,
947 class Args_05>
949 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
950 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
951 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
952 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
953 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05);
954#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 5
955
956#if BSLSTL_SET_VARIADIC_LIMIT_C >= 6
957 template <class Args_01,
958 class Args_02,
959 class Args_03,
960 class Args_04,
961 class Args_05,
962 class Args_06>
964 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
965 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
966 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
967 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
968 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
969 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06);
970#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 6
971
972#if BSLSTL_SET_VARIADIC_LIMIT_C >= 7
973 template <class Args_01,
974 class Args_02,
975 class Args_03,
976 class Args_04,
977 class Args_05,
978 class Args_06,
979 class Args_07>
981 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
982 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
983 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
984 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
985 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
986 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
987 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07);
988#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 7
989
990#if BSLSTL_SET_VARIADIC_LIMIT_C >= 8
991 template <class Args_01,
992 class Args_02,
993 class Args_03,
994 class Args_04,
995 class Args_05,
996 class Args_06,
997 class Args_07,
998 class Args_08>
1000 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1001 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1002 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1003 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1004 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1005 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1006 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
1007 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08);
1008#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 8
1009
1010#if BSLSTL_SET_VARIADIC_LIMIT_C >= 9
1011 template <class Args_01,
1012 class Args_02,
1013 class Args_03,
1014 class Args_04,
1015 class Args_05,
1016 class Args_06,
1017 class Args_07,
1018 class Args_08,
1019 class Args_09>
1021 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1022 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1023 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1024 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1025 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1026 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1027 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
1028 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
1029 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09);
1030#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 9
1031
1032#if BSLSTL_SET_VARIADIC_LIMIT_C >= 10
1033 template <class Args_01,
1034 class Args_02,
1035 class Args_03,
1036 class Args_04,
1037 class Args_05,
1038 class Args_06,
1039 class Args_07,
1040 class Args_08,
1041 class Args_09,
1042 class Args_10>
1044 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1045 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1046 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1047 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1048 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1049 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1050 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
1051 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
1052 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
1053 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10);
1054#endif // BSLSTL_SET_VARIADIC_LIMIT_C >= 10
1055
1056#else
1057// The generated code below is a workaround for the absence of perfect
1058// forwarding in some compilers.
1059
1060 template <class... Args>
1061 pair<iterator, bool> emplace(
1062 BSLS_COMPILERFEATURES_FORWARD_REF(Args)... arguments);
1063
1064 template <class... Args>
1066 BSLS_COMPILERFEATURES_FORWARD_REF(Args)... arguments);
1067
1068// }}} END GENERATED CODE
1069#endif
1070
1071 /// Remove from this set the `value_type` object at the specified
1072 /// `position`, and return an iterator referring to the element
1073 /// immediately following the removed element, or to the past-the-end
1074 /// position if the removed element was the last element in the sequence
1075 /// of elements maintained by this set. This method invalidates only
1076 /// iterators and references to the removed element and previously saved values of the `end()` iterator.
1077 ///
1078 /// \pre The behavior is undefined unless
1079 /// `position` refers to a `value_type` object in this set.
1080 iterator erase(const_iterator position);
1081
1082 /// Remove from this set the `value_type` object that is equivalent to
1083 /// the specified `key`, if such an entry exists, and return 1;
1084 /// otherwise, if there is no `value_type` object that is equivalent to
1085 /// `key`, return 0 with no other effect. This method invalidates only
1086 /// iterators and references to the removed element and previously saved
1087 /// values of the `end()` iterator.
1088 size_type erase(const key_type& key);
1089 template <class t_KEY>
1090 typename enable_if<
1091 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1092 t_KEY>::value &&
1093 !is_convertible<BSLS_COMPILERFEATURES_FORWARD_REF(t_KEY),
1094 iterator>::value &&
1095 !is_convertible<BSLS_COMPILERFEATURES_FORWARD_REF(t_KEY),
1096 const_iterator>::value,
1098 {
1099 // Implemented inline due to Sun CC compilation error.
1100 iterator it = this->find(key);
1101 if (it == end()) {
1102 return 0; // RETURN
1103 }
1104 erase(it);
1105 return 1;
1106 }
1107
1108 /// Remove from this set the `value_type` objects starting at the
1109 /// specified `first` position up to, but including the specified `last`
1110 /// position, and return `last`. This method invalidates only
1111 /// iterators and references to the removed element and previously saved values of the `end()` iterator.
1112 ///
1113 /// \pre The behavior is undefined unless
1114 /// `first` and `last` either refer to elements in this set or are the
1115 /// `end` iterator, and the `first` position is at or before the `last`
1116 /// position in the ordered sequence provided by this container.
1118
1119 /// Exchange the value and comparator of this object with those of the
1120 /// specified `other` object; also exchange the allocator of this object
1121 /// with that of `other` if the (template parameter) type `ALLOCATOR`
1122 /// has the @ref propagate_on_container_swap trait, and do not modify
1123 /// either allocator otherwise. This method provides the no-throw
1124 /// exception-safety guarantee if and only if the (template parameter)
1125 /// type `COMPARATOR` provides a no-throw swap operation, and provides
1126 /// the basic exception-safety guarantee otherwise; if an exception is
1127 /// thrown, both objects are left in valid but unspecified states. This
1128 /// operation has `O[1]` complexity if either this object was created
1129 /// with the same allocator as `other` or `ALLOCATOR` has the
1130 /// @ref propagate_on_container_swap trait; otherwise, it has `O[n + m]`
1131 /// complexity, where `n` and `m` are the number of elements in this object and `other`, respectively.
1132 ///
1133 /// \note Note that this method`s support
1134 /// for swapping objects created with different allocators when
1135 /// `ALLOCATOR` does not have the @ref propagate_on_container_swap trait is
1136 /// a departure from the C++ Standard.
1138 AllocatorTraits::is_always_equal::value
1139 && bsl::is_nothrow_swappable<COMPARATOR>::value);
1140
1141 /// Remove all entries from this set.
1142 /// \note Note that the set is empty after
1143 /// this call, but allocated memory may be retained for future use.
1145
1146 // Turn off complaints about necessarily class-defined methods.
1147 // BDE_VERIFY pragma: push
1148 // BDE_VERIFY pragma: -CD01
1149
1150 /// Return an iterator providing modifiable access to the `value_type`
1151 /// object in this set that is equivalent to the specified `key`, if
1152 /// such an entry exists, and the past-the-end (`end`) iterator
1153 /// otherwise.
1154 ///
1155 /// Note: implemented inline due to Sun CC compilation error.
1156 iterator find(const key_type& key)
1157 {
1158 return iterator(BloombergLP::bslalg::RbTreeUtil::find(
1159 d_tree, this->comparator(), key));
1160 }
1161
1162 /// Return an iterator providing modifiable access to the `value_type`
1163 /// object in this set that is equivalent to the specified `key`, if
1164 /// such an entry exists, and the past-the-end (`end`) iterator
1165 /// otherwise.
1166 ///
1167 /// Note: implemented inline due to Sun CC compilation error.
1168 template <class LOOKUP_KEY>
1169 typename bsl::enable_if<
1170 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1171 LOOKUP_KEY>::value,
1172 iterator>::type
1173 find(const LOOKUP_KEY& key)
1174 {
1175 return iterator(BloombergLP::bslalg::RbTreeUtil::find(
1176 d_tree, this->comparator(), key));
1177 }
1178
1179 /// Return an iterator providing modifiable access to the first (i.e.,
1180 /// ordered least) `value_type` object in this set greater-than or
1181 /// equal-to the specified `key`, and the past-the-end iterator if this
1182 /// set does not contain a `value_type` object greater-than or equal-to `key`.
1183 ///
1184 /// \note Note that this function returns the *first* position before
1185 /// which a `value_type` object equivalent to `key` could be inserted
1186 /// into the ordered sequence maintained by this set, while preserving
1187 /// its ordering.
1188 ///
1189 /// Note: implemented inline due to Sun CC compilation error.
1190 iterator lower_bound(const key_type& key)
1191 {
1192 return iterator(BloombergLP::bslalg::RbTreeUtil::lowerBound(
1193 d_tree, this->comparator(), key));
1194 }
1195
1196 /// Return an iterator providing modifiable access to the first (i.e.,
1197 /// ordered least) `value_type` object in this set greater-than or
1198 /// equal-to the specified `key`, and the past-the-end iterator if this
1199 /// set does not contain a `value_type` object greater-than or equal-to `key`.
1200 ///
1201 /// \note Note that this function returns the *first* position before
1202 /// which a `value_type` object equivalent to `key` could be inserted
1203 /// into the ordered sequence maintained by this set, while preserving
1204 /// its ordering.
1205 ///
1206 /// Note: implemented inline due to Sun CC compilation error.
1207 template <class LOOKUP_KEY>
1208 typename bsl::enable_if<
1209 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1210 LOOKUP_KEY>::value,
1211 iterator>::type
1212 lower_bound(const LOOKUP_KEY& key)
1213 {
1214 return iterator(BloombergLP::bslalg::RbTreeUtil::lowerBound(
1215 d_tree, this->comparator(), key));
1216 }
1217
1218 /// Return an iterator providing modifiable access to the first (i.e.,
1219 /// ordered least) `value_type` object in this set greater than the
1220 /// specified `key`, and the past-the-end iterator if this set does not contain a `value_type` object greater-than `key`.
1221 ///
1222 /// \note Note that this
1223 /// function returns the *last* position before which a `value_type`
1224 /// object equivalent to `key` could be inserted into the ordered
1225 /// sequence maintained by this set, while preserving its ordering.
1226 ///
1227 /// Note: implemented inline due to Sun CC compilation error.
1228 iterator upper_bound(const key_type& key)
1229 {
1230 return iterator(BloombergLP::bslalg::RbTreeUtil::upperBound(
1231 d_tree, this->comparator(), key));
1232 }
1233
1234 /// Return an iterator providing modifiable access to the first (i.e.,
1235 /// ordered least) `value_type` object in this set greater than the
1236 /// specified `key`, and the past-the-end iterator if this set does not contain a `value_type` object greater-than `key`.
1237 ///
1238 /// \note Note that this
1239 /// function returns the *last* position before which a `value_type`
1240 /// object equivalent to `key` could be inserted into the ordered
1241 /// sequence maintained by this set, while preserving its ordering.
1242 ///
1243 /// Note: implemented inline due to Sun CC compilation error.
1244 template <class LOOKUP_KEY>
1245 typename bsl::enable_if<
1246 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1247 LOOKUP_KEY>::value,
1248 iterator>::type
1249 upper_bound(const LOOKUP_KEY& key)
1250 {
1251 return iterator(BloombergLP::bslalg::RbTreeUtil::upperBound(
1252 d_tree, this->comparator(), key));
1253 }
1254
1255 /// Return a pair of iterators providing modifiable access to the
1256 /// sequence of `value_type` objects in this set that are equivalent to
1257 /// the specified `key`, where the first iterator is positioned at the
1258 /// start of the sequence, and the second is positioned one past the end
1259 /// of the sequence. The first returned iterator will be
1260 /// `lower_bound(key)`; the second returned iterator will be
1261 /// `upper_bound(key)`; and, if this set contains no `value_type`
1262 /// objects equivalent to `key`, then the two returned iterators will have the same value.
1263 ///
1264 /// \note Note that since a set maintains unique keys,
1265 /// the range will contain at most one element.
1266 ///
1267 /// Note: implemented inline due to Sun CC compilation error.
1268 pair<iterator, iterator> equal_range(const key_type& key)
1269 {
1270 iterator startIt = lower_bound(key);
1271 iterator endIt = startIt;
1272 if (endIt != end() && !comparator()(key, *endIt.node())) {
1273 ++endIt;
1274 }
1275 return pair<iterator, iterator>(startIt, endIt);
1276 }
1277
1278 /// Return a pair of iterators providing modifiable access to the
1279 /// sequence of `value_type` objects in this set that are equivalent to
1280 /// the specified `key`, where the first iterator is positioned at the
1281 /// start of the sequence, and the second is positioned one past the end
1282 /// of the sequence. The first returned iterator will be
1283 /// `lower_bound(key)`; the second returned iterator will be
1284 /// `upper_bound(key)`; and, if this set contains no `value_type`
1285 /// objects equivalent to `key`, then the two returned iterators will have the same value.
1286 ///
1287 /// \note Note that although a set maintains unique
1288 /// keys, the range may contain more than one element, because a
1289 /// transparent comparator may have been supplied that provides a
1290 /// different (but compatible) partitioning of keys for `LOOKUP_KEY` as
1291 /// the comparisons used to order the keys in the set.
1292 ///
1293 /// Note: implemented inline due to Sun CC compilation error.
1294 template <class LOOKUP_KEY>
1295 typename bsl::enable_if<
1296 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1297 LOOKUP_KEY>::value,
1298 pair<iterator, iterator> >::type
1299 equal_range(const LOOKUP_KEY& key)
1300 {
1301 iterator startIt = lower_bound(key);
1302 iterator endIt = startIt;
1303 if (endIt != end() && !comparator()(key, *endIt.node())) {
1304 ++endIt;
1305
1306 // Typically, even with a transparent comparator, we expect to find
1307 // either 0 or 1 matching keys. We test for those two common cases
1308 // before performing a logarithmic search via @ref upper_bound to
1309 // determine the end of the range.
1310
1311 if (endIt != end() && !comparator()(key, *endIt.node())) {
1312 endIt = upper_bound(key);
1313 }
1314 }
1315 return pair<iterator, iterator>(startIt, endIt);
1316 }
1317
1318 // BDE_VERIFY pragma: pop
1319
1320 // ACCESSORS
1321
1322 /// Return (a copy of) the allocator used for memory allocation by this
1323 /// set.
1325
1326 /// Return an iterator providing non-modifiable access to the first
1327 /// `value_type` object in the ordered sequence of `value_type` objects
1328 /// maintained by this set, or the `end` iterator if this set is empty.
1330
1331 /// Return an iterator providing non-modifiable access to the
1332 /// past-the-end element in the ordered sequence of `value_type`
1333 /// objects maintained by this set.
1335
1336 /// Return a reverse iterator providing non-modifiable access to the
1337 /// last `value_type` object in the ordered sequence of `value_type`
1338 /// objects maintained by this set, or `rend` if this object is empty.
1340
1341 /// Return a reverse iterator providing non-modifiable access to the
1342 /// prior-to-the-beginning element in the ordered sequence of
1343 /// `value_type` objects maintained by this set.
1345
1346 /// Return an iterator providing non-modifiable access to the first
1347 /// `value_type` object in the ordered sequence of `value_type` objects
1348 /// maintained by this set, or the `cend` iterator if this set is empty.
1350
1351 /// Return an iterator providing non-modifiable access to the
1352 /// past-the-end element in the ordered sequence of `value_type` objects
1353 /// maintained by this set.
1355
1356 /// Return a reverse iterator providing non-modifiable access to the
1357 /// last `value_type` object in the ordered sequence of `value_type`
1358 /// objects maintained by this set, or `crend` if this set is empty.
1360
1361 /// Return a reverse iterator providing non-modifiable access to the
1362 /// prior-to-the-beginning element in the ordered sequence of
1363 /// `value_type` objects maintained by this set.
1365
1366 /// Return `true` if this map contains an element whose key is
1367 /// equivalent to the specified `key`.
1368 bool contains(const key_type &key) const;
1369
1370 /// Return `true` if this map contains an element whose key is
1371 /// equivalent to the specified `key`.
1372 ///
1373 /// Note: implemented inline due to Sun CC compilation error
1374 template <class LOOKUP_KEY>
1375 typename bsl::enable_if<
1376 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1377 LOOKUP_KEY>::value,
1378 bool>::type
1379 contains(const LOOKUP_KEY& key) const
1380 {
1381 return find(key) != end();
1382 }
1383
1384 /// Return `true` if this set contains no elements, and `false`
1385 /// otherwise.
1386 bool empty() const BSLS_KEYWORD_NOEXCEPT;
1387
1388 /// Return the number of elements in this set.
1390
1391 /// Return a theoretical upper bound on the largest number of elements that this set could possibly hold.
1392 ///
1393 /// \note Note that there is no guarantee
1394 /// that the set can successfully grow to the returned size, or even
1395 /// close to that size without running out of resources.
1397
1398 /// Return the key-comparison functor (or function pointer) used by this
1399 /// set; if a comparator was supplied at construction, return its value,
1400 /// otherwise return a default constructed @ref key_compare object.
1401 ///
1402 /// \note Note that this comparator compares objects of type `KEY`, which is the
1403 /// type of the `value_type` objects contained in this set.
1404 key_compare key_comp() const;
1405
1406 /// Return a functor for comparing two `value_type` objects using `key_comp()`.
1407 ///
1408 /// \note Note that since `value_type` is an alias to `KEY` for
1409 /// `set`, this method returns the same functor as `key_comp()`.
1410 value_compare value_comp() const;
1411
1412 // Turn off complaints about necessarily class-defined methods.
1413 // BDE_VERIFY pragma: push
1414 // BDE_VERIFY pragma: -CD01
1415
1416 /// Return an iterator providing non-modifiable access to the
1417 /// `value_type` object in this set that is equivalent to the specified
1418 /// `key`, if such an entry exists, and the past-the-end (`end`)
1419 /// iterator otherwise.
1420 ///
1421 /// Note: implemented inline due to Sun CC compilation error.
1422 const_iterator find(const key_type& key) const
1423 {
1424 return const_iterator(BloombergLP::bslalg::RbTreeUtil::find(
1425 d_tree, this->comparator(), key));
1426 }
1427
1428 /// Return an iterator providing non-modifiable access to the
1429 /// `value_type` object in this set that is equivalent to the specified
1430 /// `key`, if such an entry exists, and the past-the-end (`end`)
1431 /// iterator otherwise.
1432 ///
1433 /// Note: implemented inline due to Sun CC compilation error.
1434 template <class LOOKUP_KEY>
1435 typename bsl::enable_if<
1436 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1437 LOOKUP_KEY>::value,
1438 const_iterator>::type
1439 find(const LOOKUP_KEY& key) const
1440 {
1441 return const_iterator(BloombergLP::bslalg::RbTreeUtil::find(
1442 d_tree, this->comparator(), key));
1443 }
1444
1445 /// Return the number of `value_type` objects within this set that are equivalent to the specified `key`.
1446 ///
1447 /// \note Note that since a set maintains
1448 /// unique keys, the returned value will be either 0 or 1.
1449 ///
1450 /// Note: implemented inline due to Sun CC compilation error.
1451 size_type count(const key_type& key) const
1452 {
1453 return (find(key) != end()) ? 1 : 0;
1454 }
1455
1456 /// Return the number of `value_type` objects within this set that are equivalent to the specified `key`.
1457 ///
1458 /// \note Note that although a set
1459 /// maintains unique keys, the returned value can be other than 0 or 1,
1460 /// because a transparent comparator may have been supplied that
1461 /// provides a different (but compatible) partitioning of keys for
1462 /// `LOOKUP_KEY` as the comparisons used to order the keys in the set.
1463 ///
1464 /// Note: implemented inline due to Sun CC compilation error.
1465 template <class LOOKUP_KEY>
1466 typename bsl::enable_if<
1467 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1468 LOOKUP_KEY>::value,
1469 size_type>::type
1470 count(const LOOKUP_KEY& key) const
1471 {
1472 int count = 0;
1473 const_iterator it = lower_bound(key);
1474
1475 while (it != end() && !comparator()(key, *it.node())) {
1476 ++it;
1477 ++count;
1478 }
1479 return count;
1480 }
1481
1482 /// Return an iterator providing non-modifiable access to the first
1483 /// (i.e., ordered least) `value_type` object in this set greater-than
1484 /// or equal-to the specified `key`, and the past-the-end iterator if
1485 /// this set does not contain a `value_type` greater-than or equal-to `key`.
1486 ///
1487 /// \note Note that this function returns the *first* position before
1488 /// which a `value_type` object equivalent to `key` could be inserted
1489 /// into the ordered sequence maintained by this set, while preserving
1490 /// its ordering.
1491 ///
1492 /// Note: implemented inline due to Sun CC compilation error.
1493 const_iterator lower_bound(const key_type& key) const
1494 {
1495 return const_iterator(BloombergLP::bslalg::RbTreeUtil::lowerBound(
1496 d_tree, this->comparator(), key));
1497 }
1498
1499 /// Return an iterator providing non-modifiable access to the first
1500 /// (i.e., ordered least) `value_type` object in this set greater-than
1501 /// or equal-to the specified `key`, and the past-the-end iterator if
1502 /// this set does not contain a `value_type` greater-than or equal-to `key`.
1503 ///
1504 /// \note Note that this function returns the *first* position before
1505 /// which a `value_type` object equivalent to `key` could be inserted
1506 /// into the ordered sequence maintained by this set, while preserving
1507 /// its ordering.
1508 ///
1509 /// Note: implemented inline due to Sun CC compilation error.
1510 template <class LOOKUP_KEY>
1511 typename bsl::enable_if<
1512 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1513 LOOKUP_KEY>::value,
1514 const_iterator>::type
1515 lower_bound(const LOOKUP_KEY& key) const
1516 {
1517 return const_iterator(BloombergLP::bslalg::RbTreeUtil::lowerBound(
1518 d_tree, this->comparator(), key));
1519 }
1520
1521 /// Return an iterator providing non-modifiable access to the first
1522 /// (i.e., ordered least) `value_type` object in this set greater than
1523 /// the specified `key`, and the past-the-end iterator if this set does
1524 /// not contain a `value_type` object greater-than `key`.
1525 ///
1526 /// \note Note that this function returns the *last* position before which a
1527 /// `value_type` object equivalent to `key` could be inserted into the
1528 /// ordered sequence maintained by this set, while preserving its
1529 /// ordering.
1530 ///
1531 /// Note: implemented inline due to Sun CC compilation error.
1532 const_iterator upper_bound(const key_type& key) const
1533 {
1534 return const_iterator(BloombergLP::bslalg::RbTreeUtil::upperBound(
1535 d_tree, this->comparator(), key));
1536 }
1537
1538 /// Return an iterator providing non-modifiable access to the first
1539 /// (i.e., ordered least) `value_type` object in this set greater than
1540 /// the specified `key`, and the past-the-end iterator if this set does
1541 /// not contain a `value_type` object greater-than `key`.
1542 ///
1543 /// \note Note that this function returns the *last* position before which a
1544 /// `value_type` object equivalent to `key` could be inserted into the
1545 /// ordered sequence maintained by this set, while preserving its
1546 /// ordering.
1547 ///
1548 /// Note: implemented inline due to Sun CC compilation error.
1549 template <class LOOKUP_KEY>
1550 typename bsl::enable_if<
1551 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1552 LOOKUP_KEY>::value,
1553 const_iterator>::type
1554 upper_bound(const LOOKUP_KEY& key) const
1555 {
1556 return const_iterator(BloombergLP::bslalg::RbTreeUtil::upperBound(
1557 d_tree, this->comparator(), key));
1558 }
1559
1560 /// Return a pair of iterators providing non-modifiable access to the
1561 /// sequence of `value_type` objects in this set that are equivalent to
1562 /// the specified `key`, where the first iterator is positioned at the
1563 /// start of the sequence, and the second is positioned one past the end
1564 /// of the sequence. The first returned iterator will be
1565 /// `lower_bound(key)`; the second returned iterator will be
1566 /// `upper_bound(key)`; and, if this set contains no `value_type`
1567 /// objects equivalent to `key`, then the two returned iterators will have the same value.
1568 ///
1569 /// \note Note that since a set maintains unique keys,
1570 /// the range will contain at most one element.
1571 ///
1572 /// Note: implemented inline due to Sun CC compilation error.
1573 pair<const_iterator, const_iterator> equal_range(const key_type& key) const
1574 {
1575 const_iterator startIt = lower_bound(key);
1576 const_iterator endIt = startIt;
1577 if (endIt != end() && !comparator()(key, *endIt.node())) {
1578 ++endIt;
1579 }
1580 return pair<const_iterator, const_iterator>(startIt, endIt);
1581 }
1582
1583 /// Return a pair of iterators providing non-modifiable access to the
1584 /// sequence of `value_type` objects in this set that are equivalent to
1585 /// the specified `key`, where the first iterator is positioned at the
1586 /// start of the sequence, and the second is positioned one past the end
1587 /// of the sequence. The first returned iterator will be
1588 /// `lower_bound(key)`; the second returned iterator will be
1589 /// `upper_bound(key)`; and, if this set contains no `value_type`
1590 /// objects equivalent to `key`, then the two returned iterators will have the same value.
1591 ///
1592 /// \note Note that although a set maintains unique
1593 /// keys, the range may contain more than one element, because a
1594 /// transparent comparator may have been supplied that provides a
1595 /// different (but compatible) partitioning of keys for `LOOKUP_KEY` as
1596 /// the comparisons used to order the keys in the set.
1597 ///
1598 /// Note: implemented inline due to Sun CC compilation error.
1599 template <class LOOKUP_KEY>
1600 typename bsl::enable_if<
1601 BloombergLP::bslmf::IsTransparentPredicate<COMPARATOR,
1602 LOOKUP_KEY>::value,
1603 pair<const_iterator, const_iterator> >::type
1604 equal_range(const LOOKUP_KEY& key) const
1605 {
1606 const_iterator startIt = lower_bound(key);
1607 const_iterator endIt = startIt;
1608 if (endIt != end() && !comparator()(key, *endIt.node())) {
1609 ++endIt;
1610
1611 // Typically, even with a transparent comparator, we expect to find
1612 // either 0 or 1 matching keys. We test for those two common cases
1613 // before performing a logarithmic search via @ref upper_bound to
1614 // determine the end of the range.
1615
1616 if (endIt != end() && !comparator()(key, *endIt.node())) {
1617 endIt = upper_bound(key);
1618 }
1619 }
1620 return pair<const_iterator, const_iterator>(startIt, endIt);
1621 }
1622
1623 // BDE_VERIFY pragma: pop
1624};
1625
1626#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
1627// CLASS TEMPLATE DEDUCTION GUIDES
1628
1629/// Deduce the template parameter `KEY` from the `value_type` of the
1630/// iterators supplied to the constructor of `set`. Deduce the template
1631/// parameters `COMPARATOR` and `ALLOCATOR` from the other parameters passed
1632/// to the constructor. This guide does not participate unless the
1633/// supplied (or defaulted) `ALLOCATOR` meets the requirements of a
1634/// standard allocator.
1635template <
1636 class INPUT_ITERATOR,
1637 class KEY = typename bsl::iterator_traits<INPUT_ITERATOR>::value_type,
1638 class COMPARATOR = std::less<KEY>,
1639 class ALLOCATOR = bsl::allocator<KEY>,
1640 class = bsl::enable_if_t<!bsl::IsStdAllocator_v<COMPARATOR>>,
1641 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
1642 >
1643set(INPUT_ITERATOR,
1644 INPUT_ITERATOR,
1645 COMPARATOR = COMPARATOR(),
1646 ALLOCATOR = ALLOCATOR())
1647-> set<KEY, COMPARATOR, ALLOCATOR>;
1648
1649/// Deduce the template parameter `KEY` from the `value_type` of the
1650/// iterators supplied to the constructor of `set`. Deduce the template
1651/// parameter `COMPARATOR` from the other parameter passed to the
1652/// constructor. This deduction guide does not participate unless the
1653/// specified `ALLOC` is convertible to `bsl::allocator<KEY>`.
1654template <
1655 class INPUT_ITERATOR,
1656 class COMPARATOR,
1657 class ALLOC,
1658 class KEY =
1659 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
1660 class DEFAULT_ALLOCATOR = bsl::allocator<KEY>,
1661 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1662 >
1663set(INPUT_ITERATOR, INPUT_ITERATOR, COMPARATOR, ALLOC *)
1664-> set<KEY, COMPARATOR>;
1665
1666/// Deduce the template parameter `KEY` from the `value_type` of the
1667/// iterators supplied to the constructor of `set`. Deduce the template
1668/// parameter `ALLOCATOR` from the other parameter passed to the
1669/// constructor. This deduction guide does not participate unless the
1670/// supplied allocator meets the requirements of a standard allocator.
1671template <
1672 class INPUT_ITERATOR,
1673 class ALLOCATOR,
1674 class KEY =
1675 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
1676 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
1677 >
1678set(INPUT_ITERATOR, INPUT_ITERATOR, ALLOCATOR)
1679-> set<KEY, std::less<KEY>, ALLOCATOR>;
1680
1681/// Deduce the template parameter `KEY` from the `value_type` of the
1682/// iterators supplied to the constructor of `set`. This deduction guide
1683/// does not participate unless the specified `ALLOC` is convertible to
1684/// `bsl::allocator<KEY>`.
1685template <
1686 class INPUT_ITERATOR,
1687 class ALLOC,
1688 class KEY =
1689 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
1690 class DEFAULT_ALLOCATOR = bsl::allocator<KEY>,
1691 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1692 >
1693set(INPUT_ITERATOR, INPUT_ITERATOR, ALLOC *)
1694-> set<KEY>;
1695
1696/// Deduce the template parameter `KEY` from the `value_type` of the
1697/// initializer_list supplied to the constructor of `set`. Deduce the
1698/// template parameters `COMPARATOR` and `ALLOCATOR` from the other
1699/// parameters passed to the constructor.
1700template <
1701 class KEY,
1702 class COMPARATOR = std::less<KEY>,
1703 class ALLOCATOR = bsl::allocator<KEY>,
1704 class = bsl::enable_if_t<!bsl::IsStdAllocator_v<COMPARATOR>>,
1705 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
1706 >
1707set(std::initializer_list<KEY>,
1708 COMPARATOR = COMPARATOR(),
1709 ALLOCATOR = ALLOCATOR())
1710-> set<KEY, COMPARATOR, ALLOCATOR>;
1711
1712/// Deduce the template parameter `KEY` from the `value_type` of the
1713/// initializer_list supplied to the constructor of `set`. Deduce the
1714/// template parameter `COMPARATOR` from the other parameter passed to the
1715/// constructor. This deduction guide does not participate unless the
1716/// specified `ALLOC` is convertible to `bsl::allocator<KEY>`.
1717template <
1718 class KEY,
1719 class COMPARATOR,
1720 class ALLOC,
1721 class DEFAULT_ALLOCATOR = bsl::allocator<KEY>,
1722 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1723 >
1724set(std::initializer_list<KEY>, COMPARATOR, ALLOC *)
1725-> set<KEY, COMPARATOR>;
1726
1727/// Deduce the template parameter `KEY` from the `value_type` of the
1728/// initializer_list supplied to the constructor of `set`. Deduce the
1729/// template parameter `ALLOCATOR` from the other parameter passed to the
1730/// constructor.
1731template <
1732 class KEY,
1733 class ALLOCATOR,
1734 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
1735 >
1736set(std::initializer_list<KEY>, ALLOCATOR)
1737-> set<KEY, std::less<KEY>, ALLOCATOR>;
1738
1739/// Deduce the template parameter `KEY` from the `value_type` of the
1740/// initializer_list supplied to the constructor of `set`. This deduction
1741/// guide does not participate unless the specified `ALLOC` is convertible
1742/// to `bsl::allocator<KEY>`.
1743template <
1744 class KEY,
1745 class ALLOC,
1746 class DEFAULT_ALLOCATOR = bsl::allocator<KEY>,
1747 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1748 >
1749set(std::initializer_list<KEY>, ALLOC *)
1750-> set<KEY>;
1751
1752#endif
1753
1754// FREE OPERATORS
1755
1756/// Return `true` if the specified `lhs` and `rhs` objects have the same
1757/// value, and `false` otherwise. Two `set` objects `lhs` and `rhs` have
1758/// the same value if they have the same number of keys, and each element
1759/// in the ordered sequence of keys of `lhs` has the same value as the
1760/// corresponding element in the ordered sequence of keys of `rhs`. This
1761/// method requires that the (template parameter) type `KEY` be
1762/// `equality-comparable` (see {Requirements on `KEY`}).
1763template <class KEY, class COMPARATOR, class ALLOCATOR>
1764bool operator==(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1765 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1766
1767#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
1768/// Return `true` if the specified `lhs` and `rhs` objects do not have the
1769/// same value, and `false` otherwise. Two `set` objects `lhs` and `rhs` do
1770/// not have the same value if they do not have the same number of keys, or
1771/// some element in the ordered sequence of keys of `lhs` does not have the
1772/// same value as the corresponding element in the ordered sequence of keys
1773/// of `rhs`. This method requires that the (template parameter) type `KEY`
1774/// be `equality-comparable` (see {Requirements on `KEY`}).
1775template <class KEY, class COMPARATOR, class ALLOCATOR>
1776bool operator!=(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1777 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1778#endif
1779
1780#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
1781
1782/// Perform a lexicographic three-way comparison of the specified `lhs` and
1783/// the specified `rhs` sets by using the comparison operators of `KEY` on
1784/// each element; return the result of that comparison.
1785template <class KEY, class COMPARATOR, class ALLOCATOR>
1786BloombergLP::bslalg::SynthThreeWayUtil::Result<KEY>
1787operator<=>(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1788 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1789
1790#else
1791
1792/// Return `true` if the value of the specified `lhs` set is
1793/// lexicographically less than that of the specified `rhs` set, and `false`
1794/// otherwise. Given iterators `i` and `j` over the respective sequences
1795/// `[lhs.begin() .. lhs.end())` and `[rhs.begin() .. rhs.end())`, the value
1796/// of set `lhs` is lexicographically less than that of set `rhs` if
1797/// `true == *i < *j` for the first pair of corresponding iterator positions
1798/// where `*i < *j` and `*j < *i` are not both `false`. If no such
1799/// corresponding iterator position exists, the value of `lhs` is
1800/// lexicographically less than that of `rhs` if `lhs.size() < rhs.size()`.
1801/// This method requires that `operator<`, inducing a total order, be
1802/// defined for `value_type`.
1803template <class KEY, class COMPARATOR, class ALLOCATOR>
1804bool operator< (const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1805 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1806
1807/// Return `true` if the value of the specified `lhs` set is
1808/// lexicographically greater than that of the specified `rhs` set, and
1809/// `false` otherwise. The value of set `lhs` is lexicographically greater
1810/// than that of set `rhs` if `rhs` is lexicographically less than `lhs`
1811/// (see `operator<`). This method requires that `operator<`, inducing a total order, be defined for `value_type`.
1812///
1813/// \note Note that this operator
1814/// returns `rhs < lhs`.
1815template <class KEY, class COMPARATOR, class ALLOCATOR>
1816bool operator> (const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1817 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1818
1819/// Return `true` if the value of the specified `lhs` set is
1820/// lexicographically less than or equal to that of the specified `rhs` set,
1821/// and `false` otherwise. The value of set `lhs` is lexicographically less
1822/// than or equal to that of set `rhs` if `rhs` is not lexicographically
1823/// less than `lhs` (see `operator<`). This method requires that
1824/// `operator<`, inducing a total order, be defined for `value_type`.
1825///
1826/// \note Note that this operator returns `!(rhs < lhs)`.
1827template <class KEY, class COMPARATOR, class ALLOCATOR>
1828bool operator<=(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1829 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1830
1831/// Return `true` if the value of the specified `lhs` set is
1832/// lexicographically greater than or equal to that of the specified `rhs`
1833/// set, and `false` otherwise. The value of set `lhs` is lexicographically
1834/// greater than or equal to that of set `rhs` if `lhs` is not
1835/// lexicographically less than `rhs` (see `operator<`). This method
1836/// requires that `operator<`, inducing a total order, be defined for `value_type`.
1837///
1838/// \note Note that this operator returns `!(lhs < rhs)`.
1839template <class KEY, class COMPARATOR, class ALLOCATOR>
1840bool operator>=(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
1841 const set<KEY, COMPARATOR, ALLOCATOR>& rhs);
1842
1843#endif // BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
1844
1845// FREE FUNCTIONS
1846
1847/// Erase all the elements in the specified set `s` that satisfy the
1848/// specified predicate `predicate`. Return the number of elements erased.
1849template <class KEY, class COMPARATOR, class ALLOCATOR, class PREDICATE>
1850typename set<KEY, COMPARATOR, ALLOCATOR>::size_type
1851erase_if(set<KEY, COMPARATOR, ALLOCATOR>& s, PREDICATE predicate);
1852
1853/// Exchange the value and comparator of the specified `a` object with those
1854/// of the specified `b` object; also exchange the allocator of `a` with
1855/// that of `b` if the (template parameter) type `ALLOCATOR` has the
1856/// @ref propagate_on_container_swap trait, and do not modify either allocator
1857/// otherwise. This function provides the no-throw exception-safety
1858/// guarantee if and only if the (template parameter) type `COMPARATOR`
1859/// provides a no-throw swap operation, and provides the basic
1860/// exception-safety guarantee otherwise; if an exception is thrown, both
1861/// objects are left in valid but unspecified states. This operation has
1862/// `O[1]` complexity if either `a` was created with the same allocator as
1863/// `b` or `ALLOCATOR` has the @ref propagate_on_container_swap trait;
1864/// otherwise, it has `O[n + m]` complexity, where `n` and `m` are the number of elements in `a` and `b`, respectively.
1865///
1866/// \note Note that this
1867/// function`s support for swapping objects created with different
1868/// allocators when `ALLOCATOR` does not have the
1869/// @ref propagate_on_container_swap trait is a departure from the C++
1870/// Standard.
1871template <class KEY, class COMPARATOR, class ALLOCATOR>
1872void swap(set<KEY, COMPARATOR, ALLOCATOR>& a,
1873 set<KEY, COMPARATOR, ALLOCATOR>& b)
1875 BSLS_KEYWORD_NOEXCEPT_OPERATOR(a.swap(b)));
1876
1877// ============================================================================
1878// TEMPLATE AND INLINE FUNCTION DEFINITIONS
1879// ============================================================================
1880
1881 // -----------------
1882 // class DataWrapper
1883 // -----------------
1884
1885// CREATORS
1886template <class KEY, class COMPARATOR, class ALLOCATOR>
1887inline
1888set<KEY, COMPARATOR, ALLOCATOR>::DataWrapper::DataWrapper(
1889 const COMPARATOR& comparator,
1890 const ALLOCATOR& basicAllocator)
1891: ::bsl::set<KEY, COMPARATOR, ALLOCATOR>::Comparator(comparator)
1892, d_pool(basicAllocator)
1893{
1894}
1895
1896template <class KEY, class COMPARATOR, class ALLOCATOR>
1897inline
1898set<KEY, COMPARATOR, ALLOCATOR>::DataWrapper::DataWrapper(
1899 BloombergLP::bslmf::MovableRef<DataWrapper> original)
1900: ::bsl::set<KEY, COMPARATOR, ALLOCATOR>::Comparator(
1901 MoveUtil::access(original).keyComparator())
1902, d_pool(MoveUtil::move(MoveUtil::access(original).d_pool))
1903{
1904}
1905
1906template <class KEY, class COMPARATOR, class ALLOCATOR>
1907inline
1908typename set<KEY, COMPARATOR, ALLOCATOR>::NodeFactory&
1909set<KEY, COMPARATOR, ALLOCATOR>::DataWrapper::nodeFactory()
1910{
1911 return d_pool;
1912}
1913
1914template <class KEY, class COMPARATOR, class ALLOCATOR>
1915inline
1916const typename set<KEY, COMPARATOR, ALLOCATOR>::NodeFactory&
1917set<KEY, COMPARATOR, ALLOCATOR>::DataWrapper::nodeFactory() const
1918{
1919 return d_pool;
1920}
1921
1922 // ---------
1923 // class set
1924 // ---------
1925
1926// PRIVATE MANIPULATORS
1927template <class KEY, class COMPARATOR, class ALLOCATOR>
1928inline
1929typename set<KEY, COMPARATOR, ALLOCATOR>::NodeFactory&
1930set<KEY, COMPARATOR, ALLOCATOR>::nodeFactory()
1931{
1932 return d_compAndAlloc.nodeFactory();
1933}
1934
1935template <class KEY, class COMPARATOR, class ALLOCATOR>
1936inline
1937typename set<KEY, COMPARATOR, ALLOCATOR>::Comparator&
1938set<KEY, COMPARATOR, ALLOCATOR>::comparator()
1939{
1940 return d_compAndAlloc;
1941}
1942
1943template <class KEY, class COMPARATOR, class ALLOCATOR>
1944inline
1945void set<KEY, COMPARATOR, ALLOCATOR>::quickSwapExchangeAllocators(set& other)
1946{
1947 BloombergLP::bslalg::RbTreeUtil::swap(&d_tree, &other.d_tree);
1948 nodeFactory().swapExchangeAllocators(other.nodeFactory());
1949
1950 // `DataWrapper` contains a `NodeFactory` object and inherits from
1951 // `Comparator`. If the empty-base-class optimization has been applied to
1952 // `Comparator`, then we must not call `swap` on it because
1953 // `sizeof(Comparator) > 0` and, therefore, we will incorrectly swap bytes
1954 // of the `NodeFactory` members!
1955
1956 if (sizeof(NodeFactory) != sizeof(DataWrapper)) {
1957 comparator().swap(other.comparator());
1958 }
1959}
1960
1961template <class KEY, class COMPARATOR, class ALLOCATOR>
1962inline
1963void set<KEY, COMPARATOR, ALLOCATOR>::quickSwapRetainAllocators(set& other)
1964{
1965 BloombergLP::bslalg::RbTreeUtil::swap(&d_tree, &other.d_tree);
1966 nodeFactory().swapRetainAllocators(other.nodeFactory());
1967
1968 // See `quickSwapExchangeAllocators` (above).
1969
1970 if (sizeof(NodeFactory) != sizeof(DataWrapper)) {
1971 comparator().swap(other.comparator());
1972 }
1973}
1974
1975template <class KEY, class COMPARATOR, class ALLOCATOR>
1976template <class INPUT_ITERATOR, class SENTINEL>
1977inline
1978void set<KEY, COMPARATOR, ALLOCATOR>::constructFromRange(INPUT_ITERATOR first,
1979 SENTINEL last)
1980{
1981 if (first == last) {
1982 return; // RETURN
1983 }
1984
1986 BloombergLP::bslstl::IteratorUtil::
1987 canCalculateInsertDistance<INPUT_ITERATOR, SENTINEL>()) {
1988 const size_type numElements = static_cast<size_type>(
1989 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last));
1990 nodeFactory().reserveNodes(numElements);
1991 }
1992
1993 BloombergLP::bslalg::RbTreeUtilTreeProctor<NodeFactory> proctor(
1994 &d_tree,
1995 &nodeFactory());
1996
1997 // The following loop guarantees amortized linear time to insert an ordered
1998 // sequence of values (as required by the standard). If the values are
1999 // in sorted order, we are guaranteed the next node can be inserted as the
2000 // right child of the previous node, and can call 'insertAt' without
2001 // 'findUniqueInsertLocation'.
2002
2003 insert(*first);
2004 BloombergLP::bslalg::RbTreeNode *prevNode = d_tree.rootNode();
2005
2006 while (++first != last) {
2007
2008 const value_type& value = *first;
2009 if (this->comparator()(value, *prevNode)) {
2010 // The values are not in order, so insert them normally.
2011 insert(value);
2012 insertFromRange(++first, last);
2013 break;
2014 }
2015
2016 if (this->comparator()(*prevNode, value)) {
2017 BloombergLP::bslalg::RbTreeNode *node =
2018 nodeFactory().emplaceIntoNewNode(value);
2019 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2020 prevNode,
2021 false,
2022 node);
2023 prevNode = node;
2024 }
2025 }
2026
2027 proctor.release();
2028}
2029
2030#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
2031 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
2032
2033template <class KEY, class COMPARATOR, class ALLOCATOR>
2034template <class INPUT_ITERATOR, class SENTINEL>
2035inline
2036void set<KEY, COMPARATOR, ALLOCATOR>::constructFromRange(
2037 INPUT_ITERATOR first,
2038 SENTINEL last,
2039 size_t numElements)
2040
2041{
2043 !BloombergLP::bslstl::IteratorUtil
2044 ::canCalculateInsertDistance<INPUT_ITERATOR, SENTINEL>()
2045 || numElements == static_cast<size_type>(
2046 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last))));
2047
2048 if (first == last) {
2049 return; // RETURN
2050 }
2051
2052 if (0 < numElements) {
2053 nodeFactory().reserveNodes(numElements);
2054 }
2055
2056 BloombergLP::bslalg::RbTreeUtilTreeProctor<NodeFactory> proctor(
2057 &d_tree,
2058 &nodeFactory());
2059
2060 // The following loop guarantees amortized linear time to insert an ordered
2061 // sequence of values (as required by the standard). If the values are
2062 // in sorted order, we are guaranteed the next node can be inserted as the
2063 // right child of the previous node, and can call 'insertAt' without
2064 // 'findUniqueInsertLocation'.
2065
2066 insert(*first); --numElements;
2067 BloombergLP::bslalg::RbTreeNode *prevNode = d_tree.rootNode();
2068
2069 while (++first != last) {
2070
2071 const value_type& value = *first;
2072 if (this->comparator()(value, *prevNode)) {
2073 // The values are not in order, so insert them normally.
2074 insert(value); --numElements;
2075 insertFromRange(++first, last, numElements);
2076 break;
2077 }
2078
2079 if (this->comparator()(*prevNode, value)) {
2080 BloombergLP::bslalg::RbTreeNode *node =
2081 nodeFactory().emplaceIntoNewNode(value);
2082 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2083 prevNode,
2084 false,
2085 node);
2086 --numElements;
2087 prevNode = node;
2088 }
2089 }
2090
2091 proctor.release();
2092}
2093
2094#endif
2095
2096template <class KEY, class COMPARATOR, class ALLOCATOR>
2097template <class INPUT_ITERATOR, class SENTINEL>
2098inline
2099void set<KEY, COMPARATOR, ALLOCATOR>::insertFromRange(INPUT_ITERATOR first,
2100 SENTINEL last)
2101{
2102 ///Implementation Notes
2103 ///--------------------
2104 // First, consume currently held free nodes. Free nodes may be available
2105 // from previous insertions that where skipped due to collisions with
2106 // keys already in the map or from nodes reserved in `constructFromRange`.
2107 //
2108 // If those nodes are insufficient *and* one can calculate the remaining
2109 // number of elements, then reserve exactly that many free nodes. There is
2110 // no more than one call to 'reserveNodes' per invocation of this method,
2111 // hence the use of 'BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY'.
2112 //
2113 // When reserving nodes, we assume the elements remaining to be inserted
2114 // have unique keys that do not duplicate any keys already in the container
2115 // If there are any duplicates, this container will have free nodes on
2116 // return from this method.
2117
2118 while (first != last) {
2119
2120 if (BloombergLP::bslstl::IteratorUtil
2121 ::canCalculateInsertDistance<INPUT_ITERATOR, SENTINEL>()
2123 !nodeFactory().hasFreeNodes())) {
2124 nodeFactory().reserveNodes(
2125 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last));
2126 }
2127
2128 insert(*first);
2129 ++first;
2130 }
2131}
2132
2133#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
2134 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
2135
2136template <class KEY, class COMPARATOR, class ALLOCATOR>
2137template <class INPUT_ITERATOR, class SENTINEL>
2138inline
2139void set<KEY, COMPARATOR, ALLOCATOR>::insertFromRange(
2140 INPUT_ITERATOR first,
2141 SENTINEL last,
2142 size_t numElements)
2143{
2145 !BloombergLP::bslstl::IteratorUtil
2146 ::canCalculateInsertDistance<INPUT_ITERATOR, SENTINEL>()
2147 || numElements == static_cast<size_type>(
2148 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last))));
2149
2150 while (first != last) {
2151
2153 !nodeFactory().hasFreeNodes())) {
2154 nodeFactory().reserveNodes(numElements);
2155 }
2156
2157 insert(*first);
2158 --numElements;
2159 ++first;
2160 }
2161}
2162
2163#endif
2164
2165// PRIVATE ACCESSORS
2166template <class KEY, class COMPARATOR, class ALLOCATOR>
2167inline
2168const typename set<KEY, COMPARATOR, ALLOCATOR>::NodeFactory&
2169set<KEY, COMPARATOR, ALLOCATOR>::nodeFactory() const
2170{
2171 return d_compAndAlloc.nodeFactory();
2172}
2173
2174template <class KEY, class COMPARATOR, class ALLOCATOR>
2175inline
2176const typename set<KEY, COMPARATOR, ALLOCATOR>::Comparator&
2177set<KEY, COMPARATOR, ALLOCATOR>::comparator() const
2178{
2179 return d_compAndAlloc;
2180}
2181
2182// CREATORS
2183template <class KEY, class COMPARATOR, class ALLOCATOR>
2184inline
2185set<KEY, COMPARATOR, ALLOCATOR>::set()
2186: d_compAndAlloc(COMPARATOR(), ALLOCATOR())
2187, d_tree()
2188{
2189}
2190
2191template <class KEY, class COMPARATOR, class ALLOCATOR>
2192inline
2193set<KEY, COMPARATOR, ALLOCATOR>::set(const ALLOCATOR& basicAllocator)
2194: d_compAndAlloc(COMPARATOR(), basicAllocator)
2195, d_tree()
2196{
2197}
2198
2199template <class KEY, class COMPARATOR, class ALLOCATOR>
2200inline
2201set<KEY, COMPARATOR, ALLOCATOR>::set(const set& original)
2202: d_compAndAlloc(original.comparator().keyComparator(),
2203 AllocatorTraits::select_on_container_copy_construction(
2204 original.nodeFactory().allocator()))
2205, d_tree()
2206{
2207 if (0 < original.size()) {
2208 nodeFactory().reserveNodes(original.size());
2209 BloombergLP::bslalg::RbTreeUtil::copyTree(&d_tree,
2210 original.d_tree,
2211 &nodeFactory());
2212 }
2213}
2214
2215template <class KEY, class COMPARATOR, class ALLOCATOR>
2216inline
2217set<KEY, COMPARATOR, ALLOCATOR>::set(
2218 BloombergLP::bslmf::MovableRef<set> original)
2219: d_compAndAlloc(MoveUtil::move(MoveUtil::access(original).d_compAndAlloc))
2220, d_tree()
2221{
2222 set& lvalue = original;
2223 BloombergLP::bslalg::RbTreeUtil::swap(&d_tree, &lvalue.d_tree);
2224}
2225
2226template <class KEY, class COMPARATOR, class ALLOCATOR>
2227inline
2228set<KEY, COMPARATOR, ALLOCATOR>::set(
2229 const set& original,
2230 const typename type_identity<ALLOCATOR>::type& basicAllocator)
2231: d_compAndAlloc(original.comparator().keyComparator(), basicAllocator)
2232, d_tree()
2233{
2234 if (0 < original.size()) {
2235 nodeFactory().reserveNodes(original.size());
2236 BloombergLP::bslalg::RbTreeUtil::copyTree(&d_tree,
2237 original.d_tree,
2238 &nodeFactory());
2239 }
2240}
2241
2242template <class KEY, class COMPARATOR, class ALLOCATOR>
2243inline
2244set<KEY, COMPARATOR, ALLOCATOR>::set(
2245 BloombergLP::bslmf::MovableRef<set> original,
2246 const typename type_identity<ALLOCATOR>::type& basicAllocator)
2247: d_compAndAlloc(MoveUtil::access(original).comparator().keyComparator(),
2248 basicAllocator)
2249, d_tree()
2250{
2251 set& lvalue = original;
2252
2254 nodeFactory().allocator() == lvalue.nodeFactory().allocator())) {
2255 d_compAndAlloc.nodeFactory().adopt(
2256 MoveUtil::move(lvalue.d_compAndAlloc.nodeFactory()));
2257 BloombergLP::bslalg::RbTreeUtil::swap(&d_tree, &lvalue.d_tree);
2258 }
2259 else {
2260 if (0 < lvalue.size()) {
2261 nodeFactory().reserveNodes(lvalue.size());
2262 BloombergLP::bslalg::RbTreeUtil::moveTree(&d_tree,
2263 &lvalue.d_tree,
2264 &nodeFactory(),
2265 &lvalue.nodeFactory());
2266 }
2267 }
2268}
2269
2270template <class KEY, class COMPARATOR, class ALLOCATOR>
2271template <class INPUT_ITERATOR>
2272inline
2273set<KEY, COMPARATOR, ALLOCATOR>::set(INPUT_ITERATOR first,
2274 INPUT_ITERATOR last,
2275 const COMPARATOR& comparator,
2276 const ALLOCATOR& basicAllocator)
2277: d_compAndAlloc(comparator, basicAllocator)
2278, d_tree()
2279{
2280 if (first != last) {
2281
2282 const size_type numElements = static_cast<size_type>(
2283 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last));
2284
2285 if (0 < numElements) {
2286 nodeFactory().reserveNodes(numElements);
2287 }
2288
2289 BloombergLP::bslalg::RbTreeUtilTreeProctor<NodeFactory> proctor(
2290 &d_tree,
2291 &nodeFactory());
2292
2293 // The following loop guarantees amortized linear time to insert an
2294 // ordered sequence of values (as required by the standard). If the
2295 // values are in sorted order, we are guaranteed the next node can be
2296 // inserted as the right child of the previous node, and can call
2297 // `insertAt` without `findUniqueInsertLocation`.
2298
2299 insert(*first);
2300 BloombergLP::bslalg::RbTreeNode *prevNode = d_tree.rootNode();
2301 while (++first != last) {
2302 // The values are not in order, so insert them normally.
2303
2304 const value_type& value = *first;
2305 if (this->comparator()(value, *prevNode)) {
2306 insert(value);
2307 insert(++first, last);
2308 break;
2309 }
2310
2311 if (this->comparator()(*prevNode, value)) {
2312 BloombergLP::bslalg::RbTreeNode *node =
2313 nodeFactory().emplaceIntoNewNode(value);
2314 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2315 prevNode,
2316 false,
2317 node);
2318 prevNode = node;
2319 }
2320 }
2321
2322 proctor.release();
2323 }
2324}
2325
2326template <class KEY, class COMPARATOR, class ALLOCATOR>
2327template <class INPUT_ITERATOR>
2328inline
2329set<KEY, COMPARATOR, ALLOCATOR>::set(INPUT_ITERATOR first,
2330 INPUT_ITERATOR last,
2331 const ALLOCATOR& basicAllocator)
2332: d_compAndAlloc(COMPARATOR(), basicAllocator)
2333, d_tree()
2334{
2335 if (first != last) {
2336
2337 const size_type numElements = static_cast<size_type>(
2338 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last));
2339
2340 if (0 < numElements) {
2341 nodeFactory().reserveNodes(numElements);
2342 }
2343
2344 BloombergLP::bslalg::RbTreeUtilTreeProctor<NodeFactory> proctor(
2345 &d_tree,
2346 &nodeFactory());
2347
2348 // The following loop guarantees amortized linear time to insert an
2349 // ordered sequence of values (as required by the standard). If the
2350 // values are in sorted order, we are guaranteed the next node can be
2351 // inserted as the right child of the previous node, and can call
2352 // `insertAt` without `findUniqueInsertLocation`.
2353
2354 insert(*first);
2355 BloombergLP::bslalg::RbTreeNode *prevNode = d_tree.rootNode();
2356 while (++first != last) {
2357 // The values are not in order, so insert them normally.
2358
2359 const value_type& value = *first;
2360 if (this->comparator()(value, *prevNode)) {
2361 insert(value);
2362 insert(++first, last);
2363 break;
2364 }
2365
2366 if (this->comparator()(*prevNode, value)) {
2367 BloombergLP::bslalg::RbTreeNode *node =
2368 nodeFactory().emplaceIntoNewNode(value);
2369 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2370 prevNode,
2371 false,
2372 node);
2373 prevNode = node;
2374 }
2375 }
2376
2377 proctor.release();
2378 }
2379}
2380
2381#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2382template <class KEY, class COMPARATOR, class ALLOCATOR>
2383inline
2384set<KEY, COMPARATOR, ALLOCATOR>::set(std::initializer_list<KEY> values,
2385 const COMPARATOR& comparator,
2386 const ALLOCATOR& basicAllocator)
2387: set(values.begin(), values.end(), comparator, basicAllocator)
2388{
2389}
2390
2391template <class KEY, class COMPARATOR, class ALLOCATOR>
2392inline
2393set<KEY, COMPARATOR, ALLOCATOR>::set(std::initializer_list<KEY> values,
2394 const ALLOCATOR& basicAllocator)
2395: set(values.begin(), values.end(), COMPARATOR(), basicAllocator)
2396{
2397}
2398#endif
2399
2400template <class KEY, class COMPARATOR, class ALLOCATOR>
2401inline
2402set<KEY, COMPARATOR, ALLOCATOR>::~set()
2403{
2404 clear();
2405}
2406
2407// MANIPULATORS
2408template <class KEY, class COMPARATOR, class ALLOCATOR>
2409inline
2410set<KEY, COMPARATOR, ALLOCATOR>&
2411set<KEY, COMPARATOR, ALLOCATOR>::operator=(const set& rhs)
2412{
2413 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this != &rhs)) {
2414 if (AllocatorTraits::propagate_on_container_copy_assignment::value) {
2415 set other(rhs, rhs.nodeFactory().allocator());
2416 quickSwapExchangeAllocators(other);
2417 }
2418 else {
2419 set other(rhs, nodeFactory().allocator());
2420 quickSwapRetainAllocators(other);
2421 }
2422 }
2423 return *this;
2424}
2425
2426template <class KEY, class COMPARATOR, class ALLOCATOR>
2427inline
2428set<KEY, COMPARATOR, ALLOCATOR>&
2429set<KEY, COMPARATOR, ALLOCATOR>::operator=(
2430 BloombergLP::bslmf::MovableRef<set> rhs)
2432 AllocatorTraits::is_always_equal::value
2433 && std::is_nothrow_move_assignable<COMPARATOR>::value)
2434{
2435 set& lvalue = rhs;
2436
2437 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this != &lvalue)) {
2438 if (nodeFactory().allocator() == lvalue.nodeFactory().allocator()) {
2439 set other(MoveUtil::move(lvalue));
2440 quickSwapRetainAllocators(other);
2441 }
2442 else if (
2443 AllocatorTraits::propagate_on_container_move_assignment::value) {
2444 set other(MoveUtil::move(lvalue));
2445 quickSwapExchangeAllocators(other);
2446 }
2447 else {
2448 set other(MoveUtil::move(lvalue), nodeFactory().allocator());
2449 quickSwapRetainAllocators(other);
2450 }
2451 }
2452 return *this;
2453}
2454
2455#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2456template <class KEY, class COMPARATOR, class ALLOCATOR>
2457inline
2458set<KEY, COMPARATOR, ALLOCATOR>&
2459set<KEY, COMPARATOR, ALLOCATOR>::operator=(std::initializer_list<KEY> values)
2460{
2461 clear();
2462 insert(values.begin(), values.end());
2463 return *this;
2464}
2465#endif
2466
2467template <class KEY, class COMPARATOR, class ALLOCATOR>
2468inline
2469typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
2470set<KEY, COMPARATOR, ALLOCATOR>::begin() BSLS_KEYWORD_NOEXCEPT
2471{
2472 return iterator(d_tree.firstNode());
2473}
2474
2475template <class KEY, class COMPARATOR, class ALLOCATOR>
2476inline
2477typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
2478set<KEY, COMPARATOR, ALLOCATOR>::end() BSLS_KEYWORD_NOEXCEPT
2479{
2480 return iterator(d_tree.sentinel());
2481}
2482
2483template <class KEY, class COMPARATOR, class ALLOCATOR>
2484inline
2485typename set<KEY, COMPARATOR, ALLOCATOR>::reverse_iterator
2486set<KEY, COMPARATOR, ALLOCATOR>::rbegin() BSLS_KEYWORD_NOEXCEPT
2487{
2488 return reverse_iterator(end());
2489}
2490
2491template <class KEY, class COMPARATOR, class ALLOCATOR>
2492inline
2493typename set<KEY, COMPARATOR, ALLOCATOR>::reverse_iterator
2494set<KEY, COMPARATOR, ALLOCATOR>::rend() BSLS_KEYWORD_NOEXCEPT
2495{
2496 return reverse_iterator(begin());
2497}
2498
2499template <class KEY, class COMPARATOR, class ALLOCATOR>
2500inline
2501pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2502set<KEY, COMPARATOR, ALLOCATOR>::insert(const value_type& value)
2503{
2504 int comparisonResult;
2505 BloombergLP::bslalg::RbTreeNode *insertLocation =
2506 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2507 &comparisonResult,
2508 &d_tree,
2509 this->comparator(),
2510 value);
2511 if (!comparisonResult) {
2512 return pair<iterator, bool>(iterator(insertLocation), false);
2513 // RETURN
2514 }
2515 BloombergLP::bslalg::RbTreeNode *node =
2516 nodeFactory().emplaceIntoNewNode(value);
2517 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2518 insertLocation,
2519 comparisonResult < 0,
2520 node);
2521 return pair<iterator, bool>(iterator(node), true);
2522}
2523
2524template <class KEY, class COMPARATOR, class ALLOCATOR>
2525inline
2526pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2527set<KEY, COMPARATOR, ALLOCATOR>::insert(
2528 BloombergLP::bslmf::MovableRef<value_type> value)
2529{
2530 value_type& lvalue = value;
2531 int comparisonResult;
2532 BloombergLP::bslalg::RbTreeNode *insertLocation =
2533 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2534 &comparisonResult,
2535 &d_tree,
2536 this->comparator(),
2537 lvalue);
2538 if (!comparisonResult) {
2539 return pair<iterator, bool>(iterator(insertLocation), false);
2540 // RETURN
2541 }
2542 BloombergLP::bslalg::RbTreeNode *node =
2543 nodeFactory().emplaceIntoNewNode(MoveUtil::move(lvalue));
2544 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2545 insertLocation,
2546 comparisonResult < 0,
2547 node);
2548 return pair<iterator, bool>(iterator(node), true);
2549}
2550
2551template <class KEY, class COMPARATOR, class ALLOCATOR>
2552inline
2553typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
2554set<KEY, COMPARATOR, ALLOCATOR>::insert(const_iterator hint,
2555 const value_type& value)
2556{
2557 BloombergLP::bslalg::RbTreeNode *hintNode =
2558 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
2559 int comparisonResult;
2560 BloombergLP::bslalg::RbTreeNode *insertLocation =
2561 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2562 &comparisonResult,
2563 &d_tree,
2564 this->comparator(),
2565 value,
2566 hintNode);
2567 if (!comparisonResult) {
2568 return iterator(insertLocation); // RETURN
2569 }
2570
2571 BloombergLP::bslalg::RbTreeNode *node =
2572 nodeFactory().emplaceIntoNewNode(value);
2573 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2574 insertLocation,
2575 comparisonResult < 0,
2576 node);
2577 return iterator(node);
2578}
2579
2580template <class KEY, class COMPARATOR, class ALLOCATOR>
2581inline
2582typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
2583set<KEY, COMPARATOR, ALLOCATOR>::insert(const_iterator hint,
2584 BloombergLP::bslmf::MovableRef<value_type> value)
2585{
2586 value_type& lvalue = value;
2587 BloombergLP::bslalg::RbTreeNode *hintNode =
2588 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
2589 int comparisonResult;
2590 BloombergLP::bslalg::RbTreeNode *insertLocation =
2591 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2592 &comparisonResult,
2593 &d_tree,
2594 this->comparator(),
2595 lvalue,
2596 hintNode);
2597 if (!comparisonResult) {
2598 return iterator(insertLocation); // RETURN
2599 }
2600
2601 BloombergLP::bslalg::RbTreeNode *node =
2602 nodeFactory().emplaceIntoNewNode(MoveUtil::move(lvalue));
2603
2604 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2605 insertLocation,
2606 comparisonResult < 0,
2607 node);
2608 return iterator(node);
2609}
2610
2611template <class KEY, class COMPARATOR, class ALLOCATOR>
2612template <class INPUT_ITERATOR>
2613inline
2614void set<KEY, COMPARATOR, ALLOCATOR>::insert(INPUT_ITERATOR first,
2615 INPUT_ITERATOR last)
2616{
2617 ///Implementation Notes
2618 ///--------------------
2619 // First, consume currently held free nodes. If those nodes are
2620 // insufficient *and* one can calculate the remaining number of elements,
2621 // then reserve exactly that many free nodes. There is no more than one
2622 // call to `reserveNodes` per invocation of this method, hence the use of
2623 // `BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY`. When reserving nodes, we
2624 // assume the elements remaining to be inserted are unique and do not
2625 // duplicate any elements already in the container. If there are any
2626 // duplicates, this container will have free nodes on return from this
2627 // method.
2628
2629 while (first != last) {
2630 if (BloombergLP::bslstl::IteratorUtil::
2631 canCalculateInsertDistance<INPUT_ITERATOR,INPUT_ITERATOR>()
2633 !nodeFactory().hasFreeNodes())) {
2634 const size_type numElements = static_cast<size_type>(
2635 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last));
2636 nodeFactory().reserveNodes(numElements);
2637 }
2638 insert(*first);
2639 ++first;
2640 }
2641}
2642
2643#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2644template <class KEY, class COMPARATOR, class ALLOCATOR>
2645inline
2646void set<KEY, COMPARATOR, ALLOCATOR>::insert(std::initializer_list<KEY> values)
2647{
2648 insert(values.begin(), values.end());
2649}
2650#endif
2651
2652#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
2653// {{{ BEGIN GENERATED CODE
2654// Command line: sim_cpp11_features.pl bslstl_set.h
2655#ifndef BSLSTL_SET_VARIADIC_LIMIT
2656#define BSLSTL_SET_VARIADIC_LIMIT 10
2657#endif
2658#ifndef BSLSTL_SET_VARIADIC_LIMIT_D
2659#define BSLSTL_SET_VARIADIC_LIMIT_D BSLSTL_SET_VARIADIC_LIMIT
2660#endif
2661#if BSLSTL_SET_VARIADIC_LIMIT_D >= 0
2662template <class KEY, class COMPARATOR, class ALLOCATOR>
2663inline
2664pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2665set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2666 )
2667{
2668 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2669 );
2670 int comparisonResult;
2671 BloombergLP::bslalg::RbTreeNode *insertLocation =
2672 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2673 &comparisonResult,
2674 &d_tree,
2675 this->comparator(),
2676 static_cast<const Node *>(node)->value());
2677 if (!comparisonResult) {
2678 nodeFactory().deleteNode(node);
2679 return pair<iterator, bool>(iterator(insertLocation), false);
2680 }
2681 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2682 insertLocation,
2683 comparisonResult < 0,
2684 node);
2685 return pair<iterator, bool>(iterator(node), true);
2686}
2687#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 0
2688
2689#if BSLSTL_SET_VARIADIC_LIMIT_D >= 1
2690template <class KEY, class COMPARATOR, class ALLOCATOR>
2691template <class Args_01>
2692inline
2693pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2694set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2695 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01)
2696{
2697 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2698 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01));
2699 int comparisonResult;
2700 BloombergLP::bslalg::RbTreeNode *insertLocation =
2701 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2702 &comparisonResult,
2703 &d_tree,
2704 this->comparator(),
2705 static_cast<const Node *>(node)->value());
2706 if (!comparisonResult) {
2707 nodeFactory().deleteNode(node);
2708 return pair<iterator, bool>(iterator(insertLocation), false);
2709 }
2710 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2711 insertLocation,
2712 comparisonResult < 0,
2713 node);
2714 return pair<iterator, bool>(iterator(node), true);
2715}
2716#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 1
2717
2718#if BSLSTL_SET_VARIADIC_LIMIT_D >= 2
2719template <class KEY, class COMPARATOR, class ALLOCATOR>
2720template <class Args_01,
2721 class Args_02>
2722inline
2723pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2724set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2725 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
2726 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02)
2727{
2728 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2729 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2730 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02));
2731 int comparisonResult;
2732 BloombergLP::bslalg::RbTreeNode *insertLocation =
2733 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2734 &comparisonResult,
2735 &d_tree,
2736 this->comparator(),
2737 static_cast<const Node *>(node)->value());
2738 if (!comparisonResult) {
2739 nodeFactory().deleteNode(node);
2740 return pair<iterator, bool>(iterator(insertLocation), false);
2741 }
2742 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2743 insertLocation,
2744 comparisonResult < 0,
2745 node);
2746 return pair<iterator, bool>(iterator(node), true);
2747}
2748#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 2
2749
2750#if BSLSTL_SET_VARIADIC_LIMIT_D >= 3
2751template <class KEY, class COMPARATOR, class ALLOCATOR>
2752template <class Args_01,
2753 class Args_02,
2754 class Args_03>
2755inline
2756pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2757set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2758 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
2759 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
2760 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03)
2761{
2762 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2763 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2764 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2765 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03));
2766 int comparisonResult;
2767 BloombergLP::bslalg::RbTreeNode *insertLocation =
2768 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2769 &comparisonResult,
2770 &d_tree,
2771 this->comparator(),
2772 static_cast<const Node *>(node)->value());
2773 if (!comparisonResult) {
2774 nodeFactory().deleteNode(node);
2775 return pair<iterator, bool>(iterator(insertLocation), false);
2776 }
2777 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2778 insertLocation,
2779 comparisonResult < 0,
2780 node);
2781 return pair<iterator, bool>(iterator(node), true);
2782}
2783#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 3
2784
2785#if BSLSTL_SET_VARIADIC_LIMIT_D >= 4
2786template <class KEY, class COMPARATOR, class ALLOCATOR>
2787template <class Args_01,
2788 class Args_02,
2789 class Args_03,
2790 class Args_04>
2791inline
2792pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2793set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2794 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
2795 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
2796 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
2797 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04)
2798{
2799 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2800 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2801 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2802 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2803 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04));
2804 int comparisonResult;
2805 BloombergLP::bslalg::RbTreeNode *insertLocation =
2806 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2807 &comparisonResult,
2808 &d_tree,
2809 this->comparator(),
2810 static_cast<const Node *>(node)->value());
2811 if (!comparisonResult) {
2812 nodeFactory().deleteNode(node);
2813 return pair<iterator, bool>(iterator(insertLocation), false);
2814 }
2815 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2816 insertLocation,
2817 comparisonResult < 0,
2818 node);
2819 return pair<iterator, bool>(iterator(node), true);
2820}
2821#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 4
2822
2823#if BSLSTL_SET_VARIADIC_LIMIT_D >= 5
2824template <class KEY, class COMPARATOR, class ALLOCATOR>
2825template <class Args_01,
2826 class Args_02,
2827 class Args_03,
2828 class Args_04,
2829 class Args_05>
2830inline
2831pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2832set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2833 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
2834 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
2835 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
2836 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
2837 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05)
2838{
2839 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2840 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2841 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2842 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2843 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
2844 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05));
2845 int comparisonResult;
2846 BloombergLP::bslalg::RbTreeNode *insertLocation =
2847 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2848 &comparisonResult,
2849 &d_tree,
2850 this->comparator(),
2851 static_cast<const Node *>(node)->value());
2852 if (!comparisonResult) {
2853 nodeFactory().deleteNode(node);
2854 return pair<iterator, bool>(iterator(insertLocation), false);
2855 }
2856 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2857 insertLocation,
2858 comparisonResult < 0,
2859 node);
2860 return pair<iterator, bool>(iterator(node), true);
2861}
2862#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 5
2863
2864#if BSLSTL_SET_VARIADIC_LIMIT_D >= 6
2865template <class KEY, class COMPARATOR, class ALLOCATOR>
2866template <class Args_01,
2867 class Args_02,
2868 class Args_03,
2869 class Args_04,
2870 class Args_05,
2871 class Args_06>
2872inline
2873pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2874set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2875 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
2876 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
2877 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
2878 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
2879 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
2880 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06)
2881{
2882 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2883 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2884 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2885 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2886 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
2887 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
2888 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06));
2889 int comparisonResult;
2890 BloombergLP::bslalg::RbTreeNode *insertLocation =
2891 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2892 &comparisonResult,
2893 &d_tree,
2894 this->comparator(),
2895 static_cast<const Node *>(node)->value());
2896 if (!comparisonResult) {
2897 nodeFactory().deleteNode(node);
2898 return pair<iterator, bool>(iterator(insertLocation), false);
2899 }
2900 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2901 insertLocation,
2902 comparisonResult < 0,
2903 node);
2904 return pair<iterator, bool>(iterator(node), true);
2905}
2906#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 6
2907
2908#if BSLSTL_SET_VARIADIC_LIMIT_D >= 7
2909template <class KEY, class COMPARATOR, class ALLOCATOR>
2910template <class Args_01,
2911 class Args_02,
2912 class Args_03,
2913 class Args_04,
2914 class Args_05,
2915 class Args_06,
2916 class Args_07>
2917inline
2918pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2919set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2920 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
2921 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
2922 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
2923 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
2924 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
2925 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
2926 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07)
2927{
2928 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2929 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2930 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2931 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2932 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
2933 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
2934 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
2935 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07));
2936 int comparisonResult;
2937 BloombergLP::bslalg::RbTreeNode *insertLocation =
2938 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2939 &comparisonResult,
2940 &d_tree,
2941 this->comparator(),
2942 static_cast<const Node *>(node)->value());
2943 if (!comparisonResult) {
2944 nodeFactory().deleteNode(node);
2945 return pair<iterator, bool>(iterator(insertLocation), false);
2946 }
2947 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2948 insertLocation,
2949 comparisonResult < 0,
2950 node);
2951 return pair<iterator, bool>(iterator(node), true);
2952}
2953#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 7
2954
2955#if BSLSTL_SET_VARIADIC_LIMIT_D >= 8
2956template <class KEY, class COMPARATOR, class ALLOCATOR>
2957template <class Args_01,
2958 class Args_02,
2959 class Args_03,
2960 class Args_04,
2961 class Args_05,
2962 class Args_06,
2963 class Args_07,
2964 class Args_08>
2965inline
2966pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
2967set<KEY, COMPARATOR, ALLOCATOR>::emplace(
2968 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
2969 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
2970 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
2971 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
2972 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
2973 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
2974 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
2975 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08)
2976{
2977 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
2978 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2979 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2980 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2981 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
2982 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
2983 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
2984 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
2985 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08));
2986 int comparisonResult;
2987 BloombergLP::bslalg::RbTreeNode *insertLocation =
2988 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
2989 &comparisonResult,
2990 &d_tree,
2991 this->comparator(),
2992 static_cast<const Node *>(node)->value());
2993 if (!comparisonResult) {
2994 nodeFactory().deleteNode(node);
2995 return pair<iterator, bool>(iterator(insertLocation), false);
2996 }
2997 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
2998 insertLocation,
2999 comparisonResult < 0,
3000 node);
3001 return pair<iterator, bool>(iterator(node), true);
3002}
3003#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 8
3004
3005#if BSLSTL_SET_VARIADIC_LIMIT_D >= 9
3006template <class KEY, class COMPARATOR, class ALLOCATOR>
3007template <class Args_01,
3008 class Args_02,
3009 class Args_03,
3010 class Args_04,
3011 class Args_05,
3012 class Args_06,
3013 class Args_07,
3014 class Args_08,
3015 class Args_09>
3016inline
3017pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
3018set<KEY, COMPARATOR, ALLOCATOR>::emplace(
3019 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3020 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3021 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3022 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
3023 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
3024 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
3025 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
3026 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
3027 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09)
3028{
3029 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3030 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3031 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3032 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3033 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
3034 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
3035 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
3036 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
3037 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
3038 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09));
3039 int comparisonResult;
3040 BloombergLP::bslalg::RbTreeNode *insertLocation =
3041 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3042 &comparisonResult,
3043 &d_tree,
3044 this->comparator(),
3045 static_cast<const Node *>(node)->value());
3046 if (!comparisonResult) {
3047 nodeFactory().deleteNode(node);
3048 return pair<iterator, bool>(iterator(insertLocation), false);
3049 }
3050 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3051 insertLocation,
3052 comparisonResult < 0,
3053 node);
3054 return pair<iterator, bool>(iterator(node), true);
3055}
3056#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 9
3057
3058#if BSLSTL_SET_VARIADIC_LIMIT_D >= 10
3059template <class KEY, class COMPARATOR, class ALLOCATOR>
3060template <class Args_01,
3061 class Args_02,
3062 class Args_03,
3063 class Args_04,
3064 class Args_05,
3065 class Args_06,
3066 class Args_07,
3067 class Args_08,
3068 class Args_09,
3069 class Args_10>
3070inline
3071pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
3072set<KEY, COMPARATOR, ALLOCATOR>::emplace(
3073 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3074 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3075 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3076 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
3077 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
3078 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
3079 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
3080 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
3081 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
3082 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10)
3083{
3084 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3085 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3086 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3087 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3088 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
3089 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
3090 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
3091 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
3092 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
3093 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09),
3094 BSLS_COMPILERFEATURES_FORWARD(Args_10, arguments_10));
3095 int comparisonResult;
3096 BloombergLP::bslalg::RbTreeNode *insertLocation =
3097 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3098 &comparisonResult,
3099 &d_tree,
3100 this->comparator(),
3101 static_cast<const Node *>(node)->value());
3102 if (!comparisonResult) {
3103 nodeFactory().deleteNode(node);
3104 return pair<iterator, bool>(iterator(insertLocation), false);
3105 }
3106 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3107 insertLocation,
3108 comparisonResult < 0,
3109 node);
3110 return pair<iterator, bool>(iterator(node), true);
3111}
3112#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 10
3113
3114
3115#if BSLSTL_SET_VARIADIC_LIMIT_D >= 0
3116template <class KEY, class COMPARATOR, class ALLOCATOR>
3117inline
3118typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3119set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint)
3120{
3121 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3122 );
3123 BloombergLP::bslalg::RbTreeNode *hintNode =
3124 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3125 int comparisonResult;
3126 BloombergLP::bslalg::RbTreeNode *insertLocation =
3127 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3128 &comparisonResult,
3129 &d_tree,
3130 this->comparator(),
3131 static_cast<const Node *>(node)->value(),
3132 hintNode);
3133 if (!comparisonResult) {
3134 nodeFactory().deleteNode(node);
3135 return iterator(insertLocation);
3136 }
3137
3138 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3139 insertLocation,
3140 comparisonResult < 0,
3141 node);
3142 return iterator(node);
3143}
3144#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 0
3145
3146#if BSLSTL_SET_VARIADIC_LIMIT_D >= 1
3147template <class KEY, class COMPARATOR, class ALLOCATOR>
3148template <class Args_01>
3149inline
3150typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3151set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3152 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01)
3153{
3154 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3155 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01));
3156 BloombergLP::bslalg::RbTreeNode *hintNode =
3157 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3158 int comparisonResult;
3159 BloombergLP::bslalg::RbTreeNode *insertLocation =
3160 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3161 &comparisonResult,
3162 &d_tree,
3163 this->comparator(),
3164 static_cast<const Node *>(node)->value(),
3165 hintNode);
3166 if (!comparisonResult) {
3167 nodeFactory().deleteNode(node);
3168 return iterator(insertLocation);
3169 }
3170
3171 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3172 insertLocation,
3173 comparisonResult < 0,
3174 node);
3175 return iterator(node);
3176}
3177#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 1
3178
3179#if BSLSTL_SET_VARIADIC_LIMIT_D >= 2
3180template <class KEY, class COMPARATOR, class ALLOCATOR>
3181template <class Args_01,
3182 class Args_02>
3183inline
3184typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3185set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3186 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3187 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02)
3188{
3189 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3190 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3191 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02));
3192 BloombergLP::bslalg::RbTreeNode *hintNode =
3193 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3194 int comparisonResult;
3195 BloombergLP::bslalg::RbTreeNode *insertLocation =
3196 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3197 &comparisonResult,
3198 &d_tree,
3199 this->comparator(),
3200 static_cast<const Node *>(node)->value(),
3201 hintNode);
3202 if (!comparisonResult) {
3203 nodeFactory().deleteNode(node);
3204 return iterator(insertLocation);
3205 }
3206
3207 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3208 insertLocation,
3209 comparisonResult < 0,
3210 node);
3211 return iterator(node);
3212}
3213#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 2
3214
3215#if BSLSTL_SET_VARIADIC_LIMIT_D >= 3
3216template <class KEY, class COMPARATOR, class ALLOCATOR>
3217template <class Args_01,
3218 class Args_02,
3219 class Args_03>
3220inline
3221typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3222set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3223 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3224 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3225 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03)
3226{
3227 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3228 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3229 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3230 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03));
3231 BloombergLP::bslalg::RbTreeNode *hintNode =
3232 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3233 int comparisonResult;
3234 BloombergLP::bslalg::RbTreeNode *insertLocation =
3235 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3236 &comparisonResult,
3237 &d_tree,
3238 this->comparator(),
3239 static_cast<const Node *>(node)->value(),
3240 hintNode);
3241 if (!comparisonResult) {
3242 nodeFactory().deleteNode(node);
3243 return iterator(insertLocation);
3244 }
3245
3246 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3247 insertLocation,
3248 comparisonResult < 0,
3249 node);
3250 return iterator(node);
3251}
3252#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 3
3253
3254#if BSLSTL_SET_VARIADIC_LIMIT_D >= 4
3255template <class KEY, class COMPARATOR, class ALLOCATOR>
3256template <class Args_01,
3257 class Args_02,
3258 class Args_03,
3259 class Args_04>
3260inline
3261typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3262set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3263 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3264 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3265 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3266 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04)
3267{
3268 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3269 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3270 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3271 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3272 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04));
3273 BloombergLP::bslalg::RbTreeNode *hintNode =
3274 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3275 int comparisonResult;
3276 BloombergLP::bslalg::RbTreeNode *insertLocation =
3277 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3278 &comparisonResult,
3279 &d_tree,
3280 this->comparator(),
3281 static_cast<const Node *>(node)->value(),
3282 hintNode);
3283 if (!comparisonResult) {
3284 nodeFactory().deleteNode(node);
3285 return iterator(insertLocation);
3286 }
3287
3288 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3289 insertLocation,
3290 comparisonResult < 0,
3291 node);
3292 return iterator(node);
3293}
3294#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 4
3295
3296#if BSLSTL_SET_VARIADIC_LIMIT_D >= 5
3297template <class KEY, class COMPARATOR, class ALLOCATOR>
3298template <class Args_01,
3299 class Args_02,
3300 class Args_03,
3301 class Args_04,
3302 class Args_05>
3303inline
3304typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3305set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3306 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3307 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3308 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3309 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
3310 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05)
3311{
3312 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3313 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3314 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3315 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3316 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
3317 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05));
3318 BloombergLP::bslalg::RbTreeNode *hintNode =
3319 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3320 int comparisonResult;
3321 BloombergLP::bslalg::RbTreeNode *insertLocation =
3322 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3323 &comparisonResult,
3324 &d_tree,
3325 this->comparator(),
3326 static_cast<const Node *>(node)->value(),
3327 hintNode);
3328 if (!comparisonResult) {
3329 nodeFactory().deleteNode(node);
3330 return iterator(insertLocation);
3331 }
3332
3333 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3334 insertLocation,
3335 comparisonResult < 0,
3336 node);
3337 return iterator(node);
3338}
3339#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 5
3340
3341#if BSLSTL_SET_VARIADIC_LIMIT_D >= 6
3342template <class KEY, class COMPARATOR, class ALLOCATOR>
3343template <class Args_01,
3344 class Args_02,
3345 class Args_03,
3346 class Args_04,
3347 class Args_05,
3348 class Args_06>
3349inline
3350typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3351set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3352 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3353 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3354 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3355 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
3356 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
3357 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06)
3358{
3359 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3360 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3361 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3362 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3363 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
3364 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
3365 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06));
3366 BloombergLP::bslalg::RbTreeNode *hintNode =
3367 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3368 int comparisonResult;
3369 BloombergLP::bslalg::RbTreeNode *insertLocation =
3370 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3371 &comparisonResult,
3372 &d_tree,
3373 this->comparator(),
3374 static_cast<const Node *>(node)->value(),
3375 hintNode);
3376 if (!comparisonResult) {
3377 nodeFactory().deleteNode(node);
3378 return iterator(insertLocation);
3379 }
3380
3381 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3382 insertLocation,
3383 comparisonResult < 0,
3384 node);
3385 return iterator(node);
3386}
3387#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 6
3388
3389#if BSLSTL_SET_VARIADIC_LIMIT_D >= 7
3390template <class KEY, class COMPARATOR, class ALLOCATOR>
3391template <class Args_01,
3392 class Args_02,
3393 class Args_03,
3394 class Args_04,
3395 class Args_05,
3396 class Args_06,
3397 class Args_07>
3398inline
3399typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3400set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3401 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3402 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3403 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3404 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
3405 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
3406 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
3407 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07)
3408{
3409 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3410 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3411 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3412 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3413 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
3414 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
3415 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
3416 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07));
3417 BloombergLP::bslalg::RbTreeNode *hintNode =
3418 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3419 int comparisonResult;
3420 BloombergLP::bslalg::RbTreeNode *insertLocation =
3421 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3422 &comparisonResult,
3423 &d_tree,
3424 this->comparator(),
3425 static_cast<const Node *>(node)->value(),
3426 hintNode);
3427 if (!comparisonResult) {
3428 nodeFactory().deleteNode(node);
3429 return iterator(insertLocation);
3430 }
3431
3432 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3433 insertLocation,
3434 comparisonResult < 0,
3435 node);
3436 return iterator(node);
3437}
3438#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 7
3439
3440#if BSLSTL_SET_VARIADIC_LIMIT_D >= 8
3441template <class KEY, class COMPARATOR, class ALLOCATOR>
3442template <class Args_01,
3443 class Args_02,
3444 class Args_03,
3445 class Args_04,
3446 class Args_05,
3447 class Args_06,
3448 class Args_07,
3449 class Args_08>
3450inline
3451typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3452set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3453 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3454 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3455 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3456 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
3457 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
3458 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
3459 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
3460 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08)
3461{
3462 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3463 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3464 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3465 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3466 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
3467 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
3468 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
3469 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
3470 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08));
3471 BloombergLP::bslalg::RbTreeNode *hintNode =
3472 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3473 int comparisonResult;
3474 BloombergLP::bslalg::RbTreeNode *insertLocation =
3475 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3476 &comparisonResult,
3477 &d_tree,
3478 this->comparator(),
3479 static_cast<const Node *>(node)->value(),
3480 hintNode);
3481 if (!comparisonResult) {
3482 nodeFactory().deleteNode(node);
3483 return iterator(insertLocation);
3484 }
3485
3486 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3487 insertLocation,
3488 comparisonResult < 0,
3489 node);
3490 return iterator(node);
3491}
3492#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 8
3493
3494#if BSLSTL_SET_VARIADIC_LIMIT_D >= 9
3495template <class KEY, class COMPARATOR, class ALLOCATOR>
3496template <class Args_01,
3497 class Args_02,
3498 class Args_03,
3499 class Args_04,
3500 class Args_05,
3501 class Args_06,
3502 class Args_07,
3503 class Args_08,
3504 class Args_09>
3505inline
3506typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3507set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3508 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3509 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3510 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3511 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
3512 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
3513 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
3514 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
3515 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
3516 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09)
3517{
3518 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3519 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3520 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3521 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3522 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
3523 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
3524 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
3525 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
3526 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
3527 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09));
3528 BloombergLP::bslalg::RbTreeNode *hintNode =
3529 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3530 int comparisonResult;
3531 BloombergLP::bslalg::RbTreeNode *insertLocation =
3532 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3533 &comparisonResult,
3534 &d_tree,
3535 this->comparator(),
3536 static_cast<const Node *>(node)->value(),
3537 hintNode);
3538 if (!comparisonResult) {
3539 nodeFactory().deleteNode(node);
3540 return iterator(insertLocation);
3541 }
3542
3543 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3544 insertLocation,
3545 comparisonResult < 0,
3546 node);
3547 return iterator(node);
3548}
3549#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 9
3550
3551#if BSLSTL_SET_VARIADIC_LIMIT_D >= 10
3552template <class KEY, class COMPARATOR, class ALLOCATOR>
3553template <class Args_01,
3554 class Args_02,
3555 class Args_03,
3556 class Args_04,
3557 class Args_05,
3558 class Args_06,
3559 class Args_07,
3560 class Args_08,
3561 class Args_09,
3562 class Args_10>
3563inline
3564typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3565set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3566 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
3567 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
3568 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
3569 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
3570 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
3571 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
3572 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
3573 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
3574 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
3575 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10)
3576{
3577 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3578 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
3579 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
3580 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
3581 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
3582 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
3583 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
3584 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
3585 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
3586 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09),
3587 BSLS_COMPILERFEATURES_FORWARD(Args_10, arguments_10));
3588 BloombergLP::bslalg::RbTreeNode *hintNode =
3589 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3590 int comparisonResult;
3591 BloombergLP::bslalg::RbTreeNode *insertLocation =
3592 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3593 &comparisonResult,
3594 &d_tree,
3595 this->comparator(),
3596 static_cast<const Node *>(node)->value(),
3597 hintNode);
3598 if (!comparisonResult) {
3599 nodeFactory().deleteNode(node);
3600 return iterator(insertLocation);
3601 }
3602
3603 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3604 insertLocation,
3605 comparisonResult < 0,
3606 node);
3607 return iterator(node);
3608}
3609#endif // BSLSTL_SET_VARIADIC_LIMIT_D >= 10
3610
3611#else
3612// The generated code below is a workaround for the absence of perfect
3613// forwarding in some compilers.
3614template <class KEY, class COMPARATOR, class ALLOCATOR>
3615template <class... Args>
3616inline
3617pair<typename set<KEY, COMPARATOR, ALLOCATOR>::iterator, bool>
3618set<KEY, COMPARATOR, ALLOCATOR>::emplace(
3619 BSLS_COMPILERFEATURES_FORWARD_REF(Args)... arguments)
3620{
3621 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3622 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
3623 int comparisonResult;
3624 BloombergLP::bslalg::RbTreeNode *insertLocation =
3625 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3626 &comparisonResult,
3627 &d_tree,
3628 this->comparator(),
3629 static_cast<const Node *>(node)->value());
3630 if (!comparisonResult) {
3631 nodeFactory().deleteNode(node);
3632 return pair<iterator, bool>(iterator(insertLocation), false);
3633 }
3634 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3635 insertLocation,
3636 comparisonResult < 0,
3637 node);
3638 return pair<iterator, bool>(iterator(node), true);
3639}
3640
3641template <class KEY, class COMPARATOR, class ALLOCATOR>
3642template <class... Args>
3643inline
3644typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3645set<KEY, COMPARATOR, ALLOCATOR>::emplace_hint(const_iterator hint,
3646 BSLS_COMPILERFEATURES_FORWARD_REF(Args)... arguments)
3647{
3648 BloombergLP::bslalg::RbTreeNode *node = nodeFactory().emplaceIntoNewNode(
3649 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
3650 BloombergLP::bslalg::RbTreeNode *hintNode =
3651 const_cast<BloombergLP::bslalg::RbTreeNode *>(hint.node());
3652 int comparisonResult;
3653 BloombergLP::bslalg::RbTreeNode *insertLocation =
3654 BloombergLP::bslalg::RbTreeUtil::findUniqueInsertLocation(
3655 &comparisonResult,
3656 &d_tree,
3657 this->comparator(),
3658 static_cast<const Node *>(node)->value(),
3659 hintNode);
3660 if (!comparisonResult) {
3661 nodeFactory().deleteNode(node);
3662 return iterator(insertLocation);
3663 }
3664
3665 BloombergLP::bslalg::RbTreeUtil::insertAt(&d_tree,
3666 insertLocation,
3667 comparisonResult < 0,
3668 node);
3669 return iterator(node);
3670}
3671// }}} END GENERATED CODE
3672#endif
3673
3674template <class KEY, class COMPARATOR, class ALLOCATOR>
3675inline
3676typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3677set<KEY, COMPARATOR, ALLOCATOR>::erase(const_iterator position)
3678{
3679 BSLS_ASSERT_SAFE(position != end());
3680
3681 BloombergLP::bslalg::RbTreeNode *node =
3682 const_cast<BloombergLP::bslalg::RbTreeNode *>(position.node());
3683 BloombergLP::bslalg::RbTreeNode *result =
3684 BloombergLP::bslalg::RbTreeUtil::next(node);
3685 BloombergLP::bslalg::RbTreeUtil::remove(&d_tree, node);
3686 nodeFactory().deleteNode(node);
3687 return iterator(result);
3688}
3689
3690template <class KEY, class COMPARATOR, class ALLOCATOR>
3691inline
3692typename set<KEY, COMPARATOR, ALLOCATOR>::size_type
3693set<KEY, COMPARATOR, ALLOCATOR>::erase(const key_type& key)
3694{
3695 const_iterator it = find(key);
3696 if (it == end()) {
3697 return 0; // RETURN
3698 }
3699 erase(it);
3700 return 1;
3701}
3702
3703template <class KEY, class COMPARATOR, class ALLOCATOR>
3704inline
3705typename set<KEY, COMPARATOR, ALLOCATOR>::iterator
3706set<KEY, COMPARATOR, ALLOCATOR>::erase(const_iterator first,
3707 const_iterator last)
3708{
3709 while (first != last) {
3710 first = erase(first);
3711 }
3712 return iterator(last.node());
3713}
3714
3715template <class KEY, class COMPARATOR, class ALLOCATOR>
3716inline
3717void set<KEY, COMPARATOR, ALLOCATOR>::swap(set& other)
3719 AllocatorTraits::is_always_equal::value
3720 && bsl::is_nothrow_swappable<COMPARATOR>::value)
3721{
3722 if (AllocatorTraits::propagate_on_container_swap::value) {
3723 quickSwapExchangeAllocators(other);
3724 }
3725 else {
3726 // C++11 behavior for member `swap`: undefined for unequal allocators.
3727 // BSLS_ASSERT(allocator() == other.allocator());
3728
3730 nodeFactory().allocator() == other.nodeFactory().allocator())) {
3731 quickSwapRetainAllocators(other);
3732 }
3733 else {
3735
3736 set toOtherCopy(MoveUtil::move(*this),
3737 other.nodeFactory().allocator());
3738 set toThisCopy(MoveUtil::move(other), nodeFactory().allocator());
3739
3740 this->quickSwapRetainAllocators(toThisCopy);
3741 other.quickSwapRetainAllocators(toOtherCopy);
3742 }
3743 }
3744}
3745
3746template <class KEY, class COMPARATOR, class ALLOCATOR>
3747inline
3748void set<KEY, COMPARATOR, ALLOCATOR>::clear() BSLS_KEYWORD_NOEXCEPT
3749{
3750 BSLS_ASSERT_SAFE(d_tree.firstNode());
3751
3752 if (d_tree.rootNode()) {
3753 BSLS_ASSERT_SAFE(0 < d_tree.numNodes());
3754 BSLS_ASSERT_SAFE(d_tree.firstNode() != d_tree.sentinel());
3755
3756 BloombergLP::bslalg::RbTreeUtil::deleteTree(&d_tree, &nodeFactory());
3757 }
3758#if defined(BSLS_ASSERT_SAFE_IS_USED)
3759 else {
3760 BSLS_ASSERT_SAFE(0 == d_tree.numNodes());
3761 BSLS_ASSERT_SAFE(d_tree.firstNode() == d_tree.sentinel());
3762 }
3763#endif
3764}
3765
3766// ACCESSORS
3767template <class KEY, class COMPARATOR, class ALLOCATOR>
3768inline
3769typename set<KEY, COMPARATOR, ALLOCATOR>::allocator_type
3770set<KEY, COMPARATOR, ALLOCATOR>::get_allocator() const BSLS_KEYWORD_NOEXCEPT
3771{
3772 return nodeFactory().allocator();
3773}
3774
3775template <class KEY, class COMPARATOR, class ALLOCATOR>
3776inline
3777typename set<KEY, COMPARATOR, ALLOCATOR>::const_iterator
3778set<KEY, COMPARATOR, ALLOCATOR>::begin() const BSLS_KEYWORD_NOEXCEPT
3779{
3780 return cbegin();
3781}
3782
3783template <class KEY, class COMPARATOR, class ALLOCATOR>
3784inline
3785typename set<KEY, COMPARATOR, ALLOCATOR>::const_iterator
3786set<KEY, COMPARATOR, ALLOCATOR>::end() const BSLS_KEYWORD_NOEXCEPT
3787{
3788 return cend();
3789}
3790
3791template <class KEY, class COMPARATOR, class ALLOCATOR>
3792inline
3793typename set<KEY, COMPARATOR, ALLOCATOR>::const_reverse_iterator
3794set<KEY, COMPARATOR, ALLOCATOR>::rbegin() const BSLS_KEYWORD_NOEXCEPT
3795{
3796 return crbegin();
3797}
3798
3799template <class KEY, class COMPARATOR, class ALLOCATOR>
3800inline
3801typename set<KEY, COMPARATOR, ALLOCATOR>::const_reverse_iterator
3802set<KEY, COMPARATOR, ALLOCATOR>::rend() const BSLS_KEYWORD_NOEXCEPT
3803{
3804 return crend();
3805}
3806
3807template <class KEY, class COMPARATOR, class ALLOCATOR>
3808inline
3809typename set<KEY, COMPARATOR, ALLOCATOR>::const_iterator
3810set<KEY, COMPARATOR, ALLOCATOR>::cbegin() const BSLS_KEYWORD_NOEXCEPT
3811{
3812 return const_iterator(d_tree.firstNode());
3813}
3814
3815template <class KEY, class COMPARATOR, class ALLOCATOR>
3816inline
3817typename set<KEY, COMPARATOR, ALLOCATOR>::const_iterator
3818set<KEY, COMPARATOR, ALLOCATOR>::cend() const BSLS_KEYWORD_NOEXCEPT
3819{
3820 return const_iterator(d_tree.sentinel());
3821}
3822
3823template <class KEY, class COMPARATOR, class ALLOCATOR>
3824inline
3825typename set<KEY, COMPARATOR, ALLOCATOR>::const_reverse_iterator
3826set<KEY, COMPARATOR, ALLOCATOR>::crbegin() const BSLS_KEYWORD_NOEXCEPT
3827{
3828 return const_reverse_iterator(end());
3829}
3830
3831template <class KEY, class COMPARATOR, class ALLOCATOR>
3832inline
3833typename set<KEY, COMPARATOR, ALLOCATOR>::const_reverse_iterator
3834set<KEY, COMPARATOR, ALLOCATOR>::crend() const BSLS_KEYWORD_NOEXCEPT
3835{
3836 return const_reverse_iterator(begin());
3837}
3838
3839template <class KEY, class COMPARATOR, class ALLOCATOR>
3840inline
3841bool set<KEY, COMPARATOR, ALLOCATOR>::contains(const key_type& key) const
3842{
3843 return find(key) != end();
3844}
3845
3846// capacity:
3847template <class KEY, class COMPARATOR, class ALLOCATOR>
3848inline
3849bool set<KEY, COMPARATOR, ALLOCATOR>::empty() const BSLS_KEYWORD_NOEXCEPT
3850{
3851 return 0 == d_tree.numNodes();
3852}
3853
3854template <class KEY, class COMPARATOR, class ALLOCATOR>
3855inline
3856typename set<KEY, COMPARATOR, ALLOCATOR>::size_type
3857set<KEY, COMPARATOR, ALLOCATOR>::size() const BSLS_KEYWORD_NOEXCEPT
3858{
3859 return d_tree.numNodes();
3860}
3861
3862template <class KEY, class COMPARATOR, class ALLOCATOR>
3863inline
3864typename set<KEY, COMPARATOR, ALLOCATOR>::size_type
3865set<KEY, COMPARATOR, ALLOCATOR>::max_size() const BSLS_KEYWORD_NOEXCEPT
3866{
3867 return AllocatorTraits::max_size(get_allocator());
3868}
3869
3870template <class KEY, class COMPARATOR, class ALLOCATOR>
3871inline
3872typename set<KEY, COMPARATOR, ALLOCATOR>::key_compare
3873set<KEY, COMPARATOR, ALLOCATOR>::key_comp() const
3874{
3875 return comparator().keyComparator();
3876}
3877
3878template <class KEY, class COMPARATOR, class ALLOCATOR>
3879inline
3880typename set<KEY, COMPARATOR, ALLOCATOR>::value_compare
3881set<KEY, COMPARATOR, ALLOCATOR>::value_comp() const
3882{
3883 return value_compare(key_comp());
3884}
3885
3886} // close namespace bsl
3887
3888// FREE OPERATORS
3889template <class KEY, class COMPARATOR, class ALLOCATOR>
3890inline
3893{
3894 return BloombergLP::bslalg::RangeCompare::equal(lhs.begin(),
3895 lhs.end(),
3896 lhs.size(),
3897 rhs.begin(),
3898 rhs.end(),
3899 rhs.size());
3900}
3901
3902#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
3903template <class KEY, class COMPARATOR, class ALLOCATOR>
3904inline
3907{
3908 return !(lhs == rhs);
3909}
3910#endif
3911
3912#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
3913
3914template <class KEY, class COMPARATOR, class ALLOCATOR>
3915inline
3916BloombergLP::bslalg::SynthThreeWayUtil::Result<KEY>
3917bsl::operator<=>(const set<KEY, COMPARATOR, ALLOCATOR>& lhs,
3918 const set<KEY, COMPARATOR, ALLOCATOR>& rhs)
3919{
3920 return bsl::lexicographical_compare_three_way(
3921 lhs.begin(),
3922 lhs.end(),
3923 rhs.begin(),
3924 rhs.end(),
3925 BloombergLP::bslalg::SynthThreeWayUtil::compare);
3926}
3927
3928#else
3929
3930template <class KEY, class COMPARATOR, class ALLOCATOR>
3931inline
3934{
3935 return 0 > BloombergLP::bslalg::RangeCompare::lexicographical(lhs.begin(),
3936 lhs.end(),
3937 lhs.size(),
3938 rhs.begin(),
3939 rhs.end(),
3940 rhs.size());
3941}
3942
3943template <class KEY, class COMPARATOR, class ALLOCATOR>
3944inline
3947{
3948 return rhs < lhs;
3949}
3950
3951template <class KEY, class COMPARATOR, class ALLOCATOR>
3952inline
3955{
3956 return !(rhs < lhs);
3957}
3958
3959template <class KEY, class COMPARATOR, class ALLOCATOR>
3960inline
3963{
3964 return !(lhs < rhs);
3965}
3966
3967#endif // BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
3968
3969// FREE FUNCTIONS
3970template <class KEY, class COMPARATOR, class ALLOCATOR, class PREDICATE>
3971inline
3973bsl::erase_if(set<KEY, COMPARATOR, ALLOCATOR>& s, PREDICATE predicate)
3974{
3975 return BloombergLP::bslstl::AlgorithmUtil::containerEraseIf(s, predicate);
3976}
3977
3978template <class KEY, class COMPARATOR, class ALLOCATOR>
3979inline
3984{
3985 a.swap(b);
3986}
3987
3988// ============================================================================
3989// TYPE TRAITS
3990// ============================================================================
3991
3992// Type traits for STL *ordered* containers:
3993//: o An ordered container defines STL iterators.
3994//: o An ordered container uses 'bslma' allocators if the (template parameter)
3995//: type 'ALLOCATOR' is convertible from 'bslma::Allocator*'.
3996
3997
3998
3999namespace bslalg {
4000
4001template <class KEY, class COMPARATOR, class ALLOCATOR>
4002struct HasStlIterators<bsl::set<KEY, COMPARATOR, ALLOCATOR> >
4004{};
4005
4006} // close namespace bslalg
4007
4008namespace bslma {
4009
4010template <class KEY, class COMPARATOR, class ALLOCATOR>
4011struct UsesBslmaAllocator<bsl::set<KEY, COMPARATOR, ALLOCATOR> >
4012 : bsl::is_convertible<Allocator*, ALLOCATOR>
4013{};
4014
4015} // close namespace bslma
4016
4017
4018
4019#else // if ! defined(DEFINED_BSLSTL_SET_H)
4020# error Not valid except when included from bslstl_set.h
4021#endif // ! defined(COMPILING_BSLSTL_SET_H)
4022
4023#endif // ! defined(INCLUDED_BSLSTL_SET_CPP03)
4024
4025// ----------------------------------------------------------------------------
4026// Copyright 2019 Bloomberg Finance L.P.
4027//
4028// Licensed under the Apache License, Version 2.0 (the "License");
4029// you may not use this file except in compliance with the License.
4030// You may obtain a copy of the License at
4031//
4032// http://www.apache.org/licenses/LICENSE-2.0
4033//
4034// Unless required by applicable law or agreed to in writing, software
4035// distributed under the License is distributed on an "AS IS" BASIS,
4036// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4037// See the License for the specific language governing permissions and
4038// limitations under the License.
4039// ----------------------------- END-OF-FILE ----------------------------------
4040
4041/** @} */
4042/** @} */
4043/** @} */
Definition bslma_bslallocator.h:588
Definition bslstl_set.h:691
pair< iterator, bool > insert(const value_type &value)
Definition bslstl_set.h:2834
bool empty() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:3219
iterator lower_bound(const key_type &key)
Definition bslstl_set.h:1522
void swap(set &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(AllocatorTraits void clear() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:1476
set &operator=(BloombergLP::bslmf::MovableRef< set > rhs) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(AllocatorTraits iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2802
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this set.
Definition bslstl_set.h:3227
iterator find(const key_type &key)
Definition bslstl_set.h:1488
const value_type & const_reference
Definition bslstl_set.h:784
void insert_range(BSLS_COMPILERFEATURES_FORWARD_REF(RANGE) range)
Definition bslstl_set.h:1342
const_reverse_iterator crbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:3196
ALLOCATOR allocator_type
Definition bslstl_set.h:782
set & operator=(const set &rhs)
Definition bslstl_set.h:2743
value_type & reference
Definition bslstl_set.h:783
reverse_iterator rbegin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2818
KEY key_type
Definition bslstl_set.h:778
BloombergLP::bslstl::TreeIterator< const value_type, Node, difference_type > iterator
Definition bslstl_set.h:793
size_type max_size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:3235
const_reverse_iterator crend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:3204
value_compare value_comp() const
Definition bslstl_set.h:3251
AllocatorTraits::pointer pointer
Definition bslstl_set.h:788
AllocatorTraits::difference_type difference_type
Definition bslstl_set.h:787
AllocatorTraits::size_type size_type
Definition bslstl_set.h:786
reverse_iterator rend() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2826
~set()
Destroy this object.
Definition bslstl_set.h:2734
BloombergLP::bslstl::TreeIterator< const value_type, Node, difference_type > const_iterator
Definition bslstl_set.h:796
COMPARATOR key_compare
Definition bslstl_set.h:780
key_compare key_comp() const
Definition bslstl_set.h:3243
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:3140
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:2810
pair< iterator, iterator > equal_range(const key_type &key)
Definition bslstl_set.h:1600
const_iterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:3180
bsl::reverse_iterator< const_iterator > const_reverse_iterator
Definition bslstl_set.h:798
bool contains(const key_type &key) const
Definition bslstl_set.h:3211
set()
Definition bslstl_set.h:2517
bsl::reverse_iterator< iterator > reverse_iterator
Definition bslstl_set.h:797
iterator upper_bound(const key_type &key)
Definition bslstl_set.h:1560
size_type count(const key_type &key) const
Definition bslstl_set.h:1783
AllocatorTraits::const_pointer const_pointer
Definition bslstl_set.h:789
COMPARATOR value_compare
Definition bslstl_set.h:781
iterator emplace_hint(const_iterator hint, Args &&... arguments)
Definition bslstl_set.h:3016
KEY value_type
Definition bslstl_set.h:779
pair< iterator, bool > emplace(Args &&... arguments)
iterator erase(const_iterator position)
Definition bslstl_set.h:3047
const_iterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_set.h:3188
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_KEYWORD_CONSTEXPR_CPP17
Definition bsls_keyword.h:639
#define BSLS_KEYWORD_NOEXCEPT_OPERATOR(...)
Definition bsls_keyword.h:677
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(...)
Definition bsls_keyword.h:676
#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
#define BSLSTL_SET_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T)
Definition bslstl_set.h:653
void swap(OptionValue &a, OptionValue &b)
Definition bdlat_valuetypefunctions.h:939
void swap(array< VALUE_TYPE, SIZE > &lhs, array< VALUE_TYPE, SIZE > &rhs)
T::const_iterator cend(const T &container)
Definition bslstl_iterator.h:1709
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:1695
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)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
deque< VALUE_TYPE, ALLOCATOR >::size_type erase(deque< VALUE_TYPE, ALLOCATOR > &deq, const BDE_OTHER_TYPE &value)
Definition bslstl_deque.h:4424
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
const from_range_t from_range
bool operator==(const memory_resource &a, const memory_resource &b)
T::const_iterator cbegin(const T &container)
Definition bslstl_iterator.h:1651
ALLOCATOR & lhs
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
deque< VALUE_TYPE, ALLOCATOR >::size_type erase_if(deque< VALUE_TYPE, ALLOCATOR > &deq, PREDICATE predicate)
Definition bslstl_deque.h:4433
bool operator!=(const memory_resource &a, const memory_resource &b)
T::const_reverse_iterator crend(const T &container)
Definition bslstl_iterator.h:1752
Definition bdlc_flathashmap.h:2218
Definition baljsn_encoder_testtypes.h:76
Definition bdlbb_blob.h:579
Definition bslma_allocatortraits.h:1089
BloombergLP::bslma::AllocatorTraits_ConstPointerType< ALLOCATOR >::type const_pointer
Definition bslma_allocatortraits.h:1183
BloombergLP::bslma::AllocatorTraits_SizeType< ALLOCATOR >::type size_type
Definition bslma_allocatortraits.h:1196
BloombergLP::bslma::AllocatorTraits_PointerType< ALLOCATOR >::type pointer
Definition bslma_allocatortraits.h:1180
BloombergLP::bslma::AllocatorTraits_DifferenceType< ALLOCATOR >::type difference_type
Definition bslma_allocatortraits.h:1193
Definition bslmf_enableif.h:530
Definition bslstl_ranges.h:301
Definition bslmf_isconvertible.h:875