BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_treenodepool_cpp03.h
Go to the documentation of this file.
1/// @file bslstl_treenodepool_cpp03.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_treenodepool_cpp03.h -*-C++-*-
8
9// Automatically generated file. **DO NOT EDIT**
10
11#ifndef INCLUDED_BSLSTL_TREENODEPOOL_CPP03
12#define INCLUDED_BSLSTL_TREENODEPOOL_CPP03
13
14/// @defgroup bslstl_treenodepool_cpp03 bslstl_treenodepool_cpp03
15/// @brief Provide C++03 implementation for bslstl_treenodepool.h
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_treenodepool_cpp03
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_treenodepool_cpp03-purpose"> Purpose</a>
25/// * <a href="#bslstl_treenodepool_cpp03-classes"> Classes </a>
26/// * <a href="#bslstl_treenodepool_cpp03-description"> Description </a>
27///
28/// # Purpose {#bslstl_treenodepool_cpp03-purpose}
29/// Provide C++03 implementation for bslstl_treenodepool.h
30///
31/// # Classes {#bslstl_treenodepool_cpp03-classes}
32/// See bslstl_treenodepool.h for list of classes
33///
34/// @see bslstl_treenodepool
35///
36/// # Description {#bslstl_treenodepool_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 Sun Sep 1 05:39:11 2024
48/// Command line: sim_cpp11_features.pl bslstl_treenodepool.h
49/// @}
50/** @} */
51/** @} */
52
53/** @addtogroup bsl
54 * @{
55 */
56/** @addtogroup bslstl
57 * @{
58 */
59/** @addtogroup bslstl_treenodepool_cpp03
60 * @{
61 */
62
63#ifdef COMPILING_BSLSTL_TREENODEPOOL_H
64
65
66namespace bslstl {
67
68 // ==================
69 // class TreeNodePool
70 // ==================
71
72/// This class provides methods for creating and deleting nodes using the
73/// appropriate allocator traits of the (template parameter) type
74/// `ALLOCATOR`. This type is intended to be used as a private base-class
75/// for a node-based container, in order to take advantage of the
76/// empty-base-class optimization in the case where the base class has 0
77/// size (as may be the case if the (template parameter) type `ALLOCATOR` is
78/// not a `bslma::Allocator`).
79///
80/// See @ref bslstl_treenodepool_cpp03
81template <class VALUE, class ALLOCATOR>
82class TreeNodePool {
83
84 /// Alias for the memory pool allocator.
85 typedef SimplePool<TreeNode<VALUE>, ALLOCATOR> Pool;
86
87 /// Alias for the allocator traits defined by `SimplePool`.
88 typedef typename Pool::AllocatorTraits AllocatorTraits;
89
90 /// This typedef is a convenient alias for the utility associated with
91 /// movable references.
92 typedef bslmf::MovableRefUtil MoveUtil;
93
94 // DATA
95 Pool d_pool; // pool for allocating memory
96
97 private:
98 // NOT IMPLEMENTED
99 TreeNodePool(const TreeNodePool&);
100 TreeNodePool& operator=(const TreeNodePool&);
101 TreeNodePool& operator=(bslmf::MovableRef<TreeNodePool>);
102
103 public:
104 // PUBLIC TYPE
105
106 /// Alias for the allocator type defined by `SimplePool`.
107 typedef typename Pool::AllocatorType AllocatorType;
108
109 /// Alias for the `size_type` of the allocator defined by `SimplePool`.
110 typedef typename AllocatorTraits::size_type size_type;
111
112 public:
113 // CREATORS
114
115 /// Create a node-pool that will use the specified `allocator` to supply
116 /// memory for allocated node objects.
117 explicit TreeNodePool(const ALLOCATOR& allocator);
118
119 /// Create a node-pool, adopting all outstanding memory allocations
120 /// associated with the specified `original` node-pool, that will use
121 /// the allocator associated with `original` to supply memory for
122 /// allocated node objects. `original` is left in a valid but
123 /// unspecified state.
124 TreeNodePool(bslmf::MovableRef<TreeNodePool> original);
125
126 // MANIPULATORS
127
128 /// Adopt all outstanding memory allocations associated with the specified node `pool`.
129 ///
130 /// \pre The behavior is undefined unless this pool
131 /// uses the same allocator as that associated with `pool`. The
132 /// behavior is also undefined unless this pool is in the
133 /// default-constructed state.
135
136 /// Return a reference providing modifiable access to the rebound allocator traits for the node-type.
137 ///
138 /// \note Note that this operation
139 /// returns a base-class (`NodeAlloc`) reference to this object.
141
142 /// Allocate a node object and copy-construct an object of the (template
143 /// parameter) type `VALUE` having the same value as the specified
144 /// `original` at the `value` attribute of the node. Return the address of the newly allocated node.
145 ///
146 /// \pre The behavior is undefined unless
147 /// `original` refers to a `TreeNode<VALUE>` object holding a valid
148 /// (initialized) value.
150
151#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
152// {{{ BEGIN GENERATED CODE
153// Command line: sim_cpp11_features.pl bslstl_treenodepool.h
154#ifndef BSLSTL_TREENODEPOOL_VARIADIC_LIMIT
155#define BSLSTL_TREENODEPOOL_VARIADIC_LIMIT 10
156#endif
157#ifndef BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A
158#define BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A BSLSTL_TREENODEPOOL_VARIADIC_LIMIT
159#endif
160#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 0
162 );
163#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 0
164
165#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 1
166 template <class Args_01>
168 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01);
169#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 1
170
171#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 2
172 template <class Args_01,
173 class Args_02>
175 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
176 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02);
177#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 2
178
179#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 3
180 template <class Args_01,
181 class Args_02,
182 class Args_03>
184 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
185 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
186 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03);
187#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 3
188
189#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 4
190 template <class Args_01,
191 class Args_02,
192 class Args_03,
193 class Args_04>
195 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
196 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
197 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
198 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04);
199#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 4
200
201#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 5
202 template <class Args_01,
203 class Args_02,
204 class Args_03,
205 class Args_04,
206 class Args_05>
208 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
209 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
210 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
211 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
212 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05);
213#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 5
214
215#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 6
216 template <class Args_01,
217 class Args_02,
218 class Args_03,
219 class Args_04,
220 class Args_05,
221 class Args_06>
223 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
224 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
225 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
226 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
227 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
228 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06);
229#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 6
230
231#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 7
232 template <class Args_01,
233 class Args_02,
234 class Args_03,
235 class Args_04,
236 class Args_05,
237 class Args_06,
238 class Args_07>
240 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
241 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
242 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
243 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
244 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
245 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
246 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07);
247#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 7
248
249#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 8
250 template <class Args_01,
251 class Args_02,
252 class Args_03,
253 class Args_04,
254 class Args_05,
255 class Args_06,
256 class Args_07,
257 class Args_08>
259 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
260 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
261 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
262 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
263 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
264 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
265 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
266 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08);
267#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 8
268
269#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 9
270 template <class Args_01,
271 class Args_02,
272 class Args_03,
273 class Args_04,
274 class Args_05,
275 class Args_06,
276 class Args_07,
277 class Args_08,
278 class Args_09>
280 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
281 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
282 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
283 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
284 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
285 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
286 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
287 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08,
288 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) args_09);
289#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 9
290
291#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 10
292 template <class Args_01,
293 class Args_02,
294 class Args_03,
295 class Args_04,
296 class Args_05,
297 class Args_06,
298 class Args_07,
299 class Args_08,
300 class Args_09,
301 class Args_10>
303 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
304 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
305 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
306 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
307 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
308 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
309 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
310 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08,
311 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) args_09,
312 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) args_10);
313#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 10
314
315#else
316// The generated code below is a workaround for the absence of perfect
317// forwarding in some compilers.
318 template <class... Args>
321// }}} END GENERATED CODE
322#endif
323
324 /// Destroy the `VALUE` value of the specified `node` and return the
325 /// memory footprint of `node` to this pool for potential reuse.
326 ///
327 /// \pre The behavior is undefined unless `node` refers to a `TreeNode<VALUE>`.
328 void deleteNode(bslalg::RbTreeNode *node);
329
330 /// Allocate a node of the type `TreeNode<VALUE>`, and move-construct an
331 /// object of the (template parameter) type `VALUE` with the (explicitly
332 /// moved) value indicated by the `value` attribute of the specified
333 /// `original` node. Return the address of the newly allocated node.
334 /// The object referred to by the `value` attribute of `original` is
335 /// left in a valid but unspecified state.
336 ///
337 /// \pre The behavior is undefined unless `original` refers to a `TreeNode<VALUE>` object holding a
338 /// valid (initialized) value.
340
341 /// Add to this pool sufficient memory to satisfy memory requests for at
342 /// least the specified `numNodes`. The additional memory is added
343 /// irrespective of the amount of free memory when called.
344 ///
345 /// \pre The behavior is undefined unless `0 < numNodes`.
346 void reserveNodes(size_type numNodes);
347
348 /// Efficiently exchange the nodes of this object with those of the
349 /// specified `other` object. This method provides the no-throw exception-safety guarantee.
350 ///
351 /// \pre The behavior is undefined unless
352 /// `allocator() == other.allocator()`.
353 void swap(TreeNodePool& other);
354
355 /// Efficiently exchange the nodes and allocator of this object with
356 /// those of the specified `other` object. This method provides the
357 /// no-throw exception-safety guarantee, *unless* swapping the
358 /// (user-supplied) allocator objects can throw.
359 void swapExchangeAllocators(TreeNodePool& other);
360
361 /// Efficiently exchange the nodes of this object with those of the
362 /// specified `other` object. This method provides the no-throw exception-safety guarantee.
363 ///
364 /// \pre The behavior is undefined unless
365 /// `allocator() == other.allocator()`.
366 void swapRetainAllocators(TreeNodePool& other);
367
368 // ACCESSORS
369
370 /// Return a reference providing non-modifiable access to the rebound allocator traits for the node-type.
371 ///
372 /// \note Note that this operation
373 /// returns a base-class (`NodeAlloc`) reference to this object.
374 const AllocatorType& allocator() const;
375
376 /// Return `true` if this object holds free (currently unused) nodes,
377 /// and `false` otherwise.
378 bool hasFreeNodes() const;
379};
380
381// ============================================================================
382// TEMPLATE AND INLINE FUNCTION DEFINITIONS
383// ============================================================================
384
385 // ------------------
386 // class TreeNodePool
387 // ------------------
388
389// CREATORS
390template <class VALUE, class ALLOCATOR>
391inline
392TreeNodePool<VALUE, ALLOCATOR>::TreeNodePool(const ALLOCATOR& allocator)
393: d_pool(allocator)
394{
395}
396
397template <class VALUE, class ALLOCATOR>
398inline
399TreeNodePool<VALUE, ALLOCATOR>::TreeNodePool(
401: d_pool(MoveUtil::move(MoveUtil::access(original).d_pool))
402{
403}
404
405// MANIPULATORS
406template <class VALUE, class ALLOCATOR>
407inline
408void
409TreeNodePool<VALUE, ALLOCATOR>::adopt(bslmf::MovableRef<TreeNodePool> pool)
410{
411 TreeNodePool& lvalue = pool;
412 d_pool.adopt(MoveUtil::move(lvalue.d_pool));
413}
414
415template <class VALUE, class ALLOCATOR>
416inline
417typename SimplePool<TreeNode<VALUE>, ALLOCATOR>::AllocatorType&
418TreeNodePool<VALUE, ALLOCATOR>::allocator()
419{
420 return d_pool.allocator();
421}
422
423template <class VALUE, class ALLOCATOR>
424inline
425bslalg::RbTreeNode *TreeNodePool<VALUE, ALLOCATOR>::cloneNode(
426 const bslalg::RbTreeNode& original)
427{
428 return emplaceIntoNewNode(
429 static_cast<const TreeNode<VALUE>&>(original).value());
430}
431
432#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
433// {{{ BEGIN GENERATED CODE
434// Command line: sim_cpp11_features.pl bslstl_treenodepool.h
435#ifndef BSLSTL_TREENODEPOOL_VARIADIC_LIMIT
436#define BSLSTL_TREENODEPOOL_VARIADIC_LIMIT 10
437#endif
438#ifndef BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B
439#define BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B BSLSTL_TREENODEPOOL_VARIADIC_LIMIT
440#endif
441#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 0
442template <class VALUE, class ALLOCATOR>
443inline
445TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
446 )
447{
448 TreeNode<VALUE> *node = d_pool.allocate();
449 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
450
451 AllocatorTraits::construct(allocator(),
452 BSLS_UTIL_ADDRESSOF(node->value()));
453 proctor.release();
454 return node;
455}
456#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 0
457
458#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 1
459template <class VALUE, class ALLOCATOR>
460template <class Args_01>
461inline
463TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
464 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01)
465{
466 TreeNode<VALUE> *node = d_pool.allocate();
467 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
468
469 AllocatorTraits::construct(allocator(),
470 BSLS_UTIL_ADDRESSOF(node->value()),
471 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01));
472 proctor.release();
473 return node;
474}
475#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 1
476
477#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 2
478template <class VALUE, class ALLOCATOR>
479template <class Args_01,
480 class Args_02>
481inline
483TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
484 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
485 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02)
486{
487 TreeNode<VALUE> *node = d_pool.allocate();
488 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
489
490 AllocatorTraits::construct(allocator(),
491 BSLS_UTIL_ADDRESSOF(node->value()),
492 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
493 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02));
494 proctor.release();
495 return node;
496}
497#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 2
498
499#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 3
500template <class VALUE, class ALLOCATOR>
501template <class Args_01,
502 class Args_02,
503 class Args_03>
504inline
506TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
507 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
508 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
509 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03)
510{
511 TreeNode<VALUE> *node = d_pool.allocate();
512 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
513
514 AllocatorTraits::construct(allocator(),
515 BSLS_UTIL_ADDRESSOF(node->value()),
516 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
517 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
518 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03));
519 proctor.release();
520 return node;
521}
522#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 3
523
524#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 4
525template <class VALUE, class ALLOCATOR>
526template <class Args_01,
527 class Args_02,
528 class Args_03,
529 class Args_04>
530inline
532TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
533 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
534 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
535 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
536 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04)
537{
538 TreeNode<VALUE> *node = d_pool.allocate();
539 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
540
541 AllocatorTraits::construct(allocator(),
542 BSLS_UTIL_ADDRESSOF(node->value()),
543 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
544 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
545 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
546 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04));
547 proctor.release();
548 return node;
549}
550#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 4
551
552#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 5
553template <class VALUE, class ALLOCATOR>
554template <class Args_01,
555 class Args_02,
556 class Args_03,
557 class Args_04,
558 class Args_05>
559inline
561TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
562 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
563 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
564 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
565 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
566 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05)
567{
568 TreeNode<VALUE> *node = d_pool.allocate();
569 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
570
571 AllocatorTraits::construct(allocator(),
572 BSLS_UTIL_ADDRESSOF(node->value()),
573 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
574 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
575 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
576 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
577 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05));
578 proctor.release();
579 return node;
580}
581#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 5
582
583#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 6
584template <class VALUE, class ALLOCATOR>
585template <class Args_01,
586 class Args_02,
587 class Args_03,
588 class Args_04,
589 class Args_05,
590 class Args_06>
591inline
593TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
594 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
595 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
596 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
597 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
598 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
599 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06)
600{
601 TreeNode<VALUE> *node = d_pool.allocate();
602 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
603
604 AllocatorTraits::construct(allocator(),
605 BSLS_UTIL_ADDRESSOF(node->value()),
606 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
607 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
608 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
609 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
610 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
611 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06));
612 proctor.release();
613 return node;
614}
615#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 6
616
617#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 7
618template <class VALUE, class ALLOCATOR>
619template <class Args_01,
620 class Args_02,
621 class Args_03,
622 class Args_04,
623 class Args_05,
624 class Args_06,
625 class Args_07>
626inline
628TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
629 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
630 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
631 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
632 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
633 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
634 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
635 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07)
636{
637 TreeNode<VALUE> *node = d_pool.allocate();
638 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
639
640 AllocatorTraits::construct(allocator(),
641 BSLS_UTIL_ADDRESSOF(node->value()),
642 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
643 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
644 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
645 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
646 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
647 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06),
648 BSLS_COMPILERFEATURES_FORWARD(Args_07,args_07));
649 proctor.release();
650 return node;
651}
652#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 7
653
654#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 8
655template <class VALUE, class ALLOCATOR>
656template <class Args_01,
657 class Args_02,
658 class Args_03,
659 class Args_04,
660 class Args_05,
661 class Args_06,
662 class Args_07,
663 class Args_08>
664inline
666TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
667 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
668 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
669 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
670 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
671 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
672 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
673 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
674 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08)
675{
676 TreeNode<VALUE> *node = d_pool.allocate();
677 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
678
679 AllocatorTraits::construct(allocator(),
680 BSLS_UTIL_ADDRESSOF(node->value()),
681 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
682 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
683 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
684 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
685 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
686 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06),
687 BSLS_COMPILERFEATURES_FORWARD(Args_07,args_07),
688 BSLS_COMPILERFEATURES_FORWARD(Args_08,args_08));
689 proctor.release();
690 return node;
691}
692#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 8
693
694#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 9
695template <class VALUE, class ALLOCATOR>
696template <class Args_01,
697 class Args_02,
698 class Args_03,
699 class Args_04,
700 class Args_05,
701 class Args_06,
702 class Args_07,
703 class Args_08,
704 class Args_09>
705inline
707TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
708 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
709 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
710 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
711 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
712 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
713 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
714 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
715 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08,
716 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) args_09)
717{
718 TreeNode<VALUE> *node = d_pool.allocate();
719 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
720
721 AllocatorTraits::construct(allocator(),
722 BSLS_UTIL_ADDRESSOF(node->value()),
723 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
724 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
725 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
726 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
727 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
728 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06),
729 BSLS_COMPILERFEATURES_FORWARD(Args_07,args_07),
730 BSLS_COMPILERFEATURES_FORWARD(Args_08,args_08),
731 BSLS_COMPILERFEATURES_FORWARD(Args_09,args_09));
732 proctor.release();
733 return node;
734}
735#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 9
736
737#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 10
738template <class VALUE, class ALLOCATOR>
739template <class Args_01,
740 class Args_02,
741 class Args_03,
742 class Args_04,
743 class Args_05,
744 class Args_06,
745 class Args_07,
746 class Args_08,
747 class Args_09,
748 class Args_10>
749inline
751TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
752 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
753 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
754 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
755 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
756 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
757 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
758 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
759 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08,
760 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) args_09,
761 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) args_10)
762{
763 TreeNode<VALUE> *node = d_pool.allocate();
764 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
765
766 AllocatorTraits::construct(allocator(),
767 BSLS_UTIL_ADDRESSOF(node->value()),
768 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
769 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
770 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
771 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
772 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
773 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06),
774 BSLS_COMPILERFEATURES_FORWARD(Args_07,args_07),
775 BSLS_COMPILERFEATURES_FORWARD(Args_08,args_08),
776 BSLS_COMPILERFEATURES_FORWARD(Args_09,args_09),
777 BSLS_COMPILERFEATURES_FORWARD(Args_10,args_10));
778 proctor.release();
779 return node;
780}
781#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 10
782
783#else
784// The generated code below is a workaround for the absence of perfect
785// forwarding in some compilers.
786template <class VALUE, class ALLOCATOR>
787template <class... Args>
788inline
790TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
792{
793 TreeNode<VALUE> *node = d_pool.allocate();
794 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
795
796 AllocatorTraits::construct(allocator(),
797 BSLS_UTIL_ADDRESSOF(node->value()),
798 BSLS_COMPILERFEATURES_FORWARD(Args,args)...);
799 proctor.release();
800 return node;
801}
802// }}} END GENERATED CODE
803#endif
804
805template <class VALUE, class ALLOCATOR>
806inline
807void TreeNodePool<VALUE, ALLOCATOR>::deleteNode(bslalg::RbTreeNode *node)
808{
809 BSLS_ASSERT(node);
810
811 TreeNode<VALUE> *treeNode = static_cast<TreeNode<VALUE> *>(node);
812 AllocatorTraits::destroy(allocator(),
813 BSLS_UTIL_ADDRESSOF(treeNode->value()));
814 d_pool.deallocate(treeNode);
815}
816
817template <class VALUE, class ALLOCATOR>
818inline
820TreeNodePool<VALUE, ALLOCATOR>::moveIntoNewNode(bslalg::RbTreeNode *original)
821{
822 return emplaceIntoNewNode(
823 MoveUtil::move(static_cast<TreeNode<VALUE> *>(original)->value()));
824}
825
826template <class VALUE, class ALLOCATOR>
827inline
828void TreeNodePool<VALUE, ALLOCATOR>::reserveNodes(size_type numNodes)
829{
830 BSLS_ASSERT_SAFE(0 < numNodes);
831
832 d_pool.reserve(numNodes);
833}
834
835template <class VALUE, class ALLOCATOR>
836inline
837void TreeNodePool<VALUE, ALLOCATOR>::swap(
838 TreeNodePool<VALUE, ALLOCATOR>& other)
839{
840 BSLS_ASSERT_SAFE(allocator() == other.allocator());
841
842 d_pool.swap(other.d_pool);
843}
844
845template <class VALUE, class ALLOCATOR>
846inline
847void TreeNodePool<VALUE, ALLOCATOR>::swapExchangeAllocators(
848 TreeNodePool<VALUE, ALLOCATOR>& other)
849{
850 d_pool.quickSwapExchangeAllocators(other.d_pool);
851}
852
853template <class VALUE, class ALLOCATOR>
854inline
855void TreeNodePool<VALUE, ALLOCATOR>::swapRetainAllocators(
856 TreeNodePool<VALUE, ALLOCATOR>& other)
857{
858 BSLS_ASSERT_SAFE(allocator() == other.allocator());
859
860 d_pool.quickSwapRetainAllocators(other.d_pool);
861}
862
863// ACCESSORS
864template <class VALUE, class ALLOCATOR>
865inline
866const typename SimplePool<TreeNode<VALUE>, ALLOCATOR>::AllocatorType&
867TreeNodePool<VALUE, ALLOCATOR>::allocator() const
868{
869 return d_pool.allocator();
870}
871
872template <class VALUE, class ALLOCATOR>
873inline
874bool TreeNodePool<VALUE, ALLOCATOR>::hasFreeNodes() const
875{
876 return d_pool.hasFreeBlocks();
877}
878
879} // close package namespace
880
881
882#else // if ! defined(DEFINED_BSLSTL_TREENODEPOOL_H)
883# error Not valid except when included from bslstl_treenodepool.h
884#endif // ! defined(COMPILING_BSLSTL_TREENODEPOOL_H)
885
886#endif // ! defined(INCLUDED_BSLSTL_TREENODEPOOL_CPP03)
887
888// ----------------------------------------------------------------------------
889// Copyright 2019 Bloomberg Finance L.P.
890//
891// Licensed under the Apache License, Version 2.0 (the "License");
892// you may not use this file except in compliance with the License.
893// You may obtain a copy of the License at
894//
895// http://www.apache.org/licenses/LICENSE-2.0
896//
897// Unless required by applicable law or agreed to in writing, software
898// distributed under the License is distributed on an "AS IS" BASIS,
899// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
900// See the License for the specific language governing permissions and
901// limitations under the License.
902// ----------------------------- END-OF-FILE ----------------------------------
903
904/** @} */
905/** @} */
906/** @} */
Definition bslalg_rbtreenode.h:377
Definition bslma_deallocatorproctor.h:312
Definition bslmf_movableref.h:752
Types::AllocatorType AllocatorType
Definition bslstl_simplepool.h:343
Types::AllocatorTraits AllocatorTraits
Definition bslstl_simplepool.h:347
void reserveNodes(size_type numNodes)
Definition bslstl_treenodepool.h:524
void adopt(bslmf::MovableRef< TreeNodePool > pool)
Definition bslstl_treenodepool.h:460
AllocatorTraits::size_type size_type
Alias for the size_type of the allocator defined by SimplePool.
Definition bslstl_treenodepool.h:323
bslalg::RbTreeNode * moveIntoNewNode(bslalg::RbTreeNode *original)
Definition bslstl_treenodepool.h:516
Pool::AllocatorType AllocatorType
Alias for the allocator type defined by SimplePool.
Definition bslstl_treenodepool.h:320
void swap(TreeNodePool &other)
Definition bslstl_treenodepool.h:533
AllocatorType & allocator()
Definition bslstl_treenodepool.h:469
bslalg::RbTreeNode * emplaceIntoNewNode(Args &&... args)
Definition bslstl_treenodepool.h:488
void swapExchangeAllocators(TreeNodePool &other)
Definition bslstl_treenodepool.h:543
void deleteNode(bslalg::RbTreeNode *node)
Definition bslstl_treenodepool.h:503
bool hasFreeNodes() const
Definition bslstl_treenodepool.h:570
bslalg::RbTreeNode * cloneNode(const bslalg::RbTreeNode &original)
Definition bslstl_treenodepool.h:476
void swapRetainAllocators(TreeNodePool &other)
Definition bslstl_treenodepool.h:551
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#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_UTIL_ADDRESSOF(OBJ)
Definition bsls_util.h:296
Definition bslstl_algorithm.h:84
Definition bslmf_movableref.h:795