BDE 4.14.0 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
129 /// specified node `pool`. The behavior is undefined unless this pool
130 /// uses the same allocator as that associated with `pool`. The
131 /// behavior is also undefined unless this pool is in the
132 /// default-constructed state.
134
135 /// Return a reference providing modifiable access to the rebound
136 /// allocator traits for the node-type. Note that this operation
137 /// returns a base-class (`NodeAlloc`) reference to this object.
139
140 /// Allocate a node object and copy-construct an object of the (template
141 /// parameter) type `VALUE` having the same value as the specified
142 /// `original` at the `value` attribute of the node. Return the address
143 /// of the newly allocated node. The behavior is undefined unless
144 /// `original` refers to a `TreeNode<VALUE>` object holding a valid
145 /// (initialized) value.
147
148#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
149// {{{ BEGIN GENERATED CODE
150// Command line: sim_cpp11_features.pl bslstl_treenodepool.h
151#ifndef BSLSTL_TREENODEPOOL_VARIADIC_LIMIT
152#define BSLSTL_TREENODEPOOL_VARIADIC_LIMIT 10
153#endif
154#ifndef BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A
155#define BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A BSLSTL_TREENODEPOOL_VARIADIC_LIMIT
156#endif
157#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 0
159 );
160#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 0
161
162#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 1
163 template <class Args_01>
165 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01);
166#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 1
167
168#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 2
169 template <class Args_01,
170 class Args_02>
172 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
173 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02);
174#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 2
175
176#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 3
177 template <class Args_01,
178 class Args_02,
179 class Args_03>
181 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
182 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
183 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03);
184#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 3
185
186#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 4
187 template <class Args_01,
188 class Args_02,
189 class Args_03,
190 class Args_04>
192 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
193 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
194 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
195 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04);
196#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 4
197
198#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 5
199 template <class Args_01,
200 class Args_02,
201 class Args_03,
202 class Args_04,
203 class Args_05>
205 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
206 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
207 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
208 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
209 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05);
210#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 5
211
212#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 6
213 template <class Args_01,
214 class Args_02,
215 class Args_03,
216 class Args_04,
217 class Args_05,
218 class Args_06>
220 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
221 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
222 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
223 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
224 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
225 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06);
226#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 6
227
228#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 7
229 template <class Args_01,
230 class Args_02,
231 class Args_03,
232 class Args_04,
233 class Args_05,
234 class Args_06,
235 class Args_07>
237 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
238 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
239 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
240 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
241 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
242 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
243 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07);
244#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 7
245
246#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 8
247 template <class Args_01,
248 class Args_02,
249 class Args_03,
250 class Args_04,
251 class Args_05,
252 class Args_06,
253 class Args_07,
254 class Args_08>
256 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
257 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
258 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
259 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
260 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
261 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
262 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
263 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08);
264#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 8
265
266#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 9
267 template <class Args_01,
268 class Args_02,
269 class Args_03,
270 class Args_04,
271 class Args_05,
272 class Args_06,
273 class Args_07,
274 class Args_08,
275 class Args_09>
277 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
278 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
279 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
280 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
281 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
282 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
283 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
284 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08,
285 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) args_09);
286#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 9
287
288#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 10
289 template <class Args_01,
290 class Args_02,
291 class Args_03,
292 class Args_04,
293 class Args_05,
294 class Args_06,
295 class Args_07,
296 class Args_08,
297 class Args_09,
298 class Args_10>
300 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
301 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
302 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
303 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
304 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
305 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
306 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
307 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08,
308 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) args_09,
309 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) args_10);
310#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_A >= 10
311
312#else
313// The generated code below is a workaround for the absence of perfect
314// forwarding in some compilers.
315 template <class... Args>
318// }}} END GENERATED CODE
319#endif
320
321 /// Destroy the `VALUE` value of the specified `node` and return the
322 /// memory footprint of `node` to this pool for potential reuse. The
323 /// behavior is undefined unless `node` refers to a `TreeNode<VALUE>`.
324 void deleteNode(bslalg::RbTreeNode *node);
325
326 /// Allocate a node of the type `TreeNode<VALUE>`, and move-construct an
327 /// object of the (template parameter) type `VALUE` with the (explicitly
328 /// moved) value indicated by the `value` attribute of the specified
329 /// `original` node. Return the address of the newly allocated node.
330 /// The object referred to by the `value` attribute of `original` is
331 /// left in a valid but unspecified state. The behavior is undefined
332 /// unless `original` refers to a `TreeNode<VALUE>` object holding a
333 /// valid (initialized) value.
335
336 /// Add to this pool sufficient memory to satisfy memory requests for at
337 /// least the specified `numNodes`. The additional memory is added
338 /// irrespective of the amount of free memory when called. The behavior
339 /// is undefined unless `0 < numNodes`.
340 void reserveNodes(size_type numNodes);
341
342 /// Efficiently exchange the nodes of this object with those of the
343 /// specified `other` object. This method provides the no-throw
344 /// exception-safety guarantee. The behavior is undefined unless
345 /// `allocator() == other.allocator()`.
346 void swap(TreeNodePool& other);
347
348 /// Efficiently exchange the nodes and allocator of this object with
349 /// those of the specified `other` object. This method provides the
350 /// no-throw exception-safety guarantee, *unless* swapping the
351 /// (user-supplied) allocator objects can throw.
352 void swapExchangeAllocators(TreeNodePool& other);
353
354 /// Efficiently exchange the nodes of this object with those of the
355 /// specified `other` object. This method provides the no-throw
356 /// exception-safety guarantee. The behavior is undefined unless
357 /// `allocator() == other.allocator()`.
358 void swapRetainAllocators(TreeNodePool& other);
359
360 // ACCESSORS
361
362 /// Return a reference providing non-modifiable access to the rebound
363 /// allocator traits for the node-type. Note that this operation
364 /// returns a base-class (`NodeAlloc`) reference to this object.
365 const AllocatorType& allocator() const;
366
367 /// Return `true` if this object holds free (currently unused) nodes,
368 /// and `false` otherwise.
369 bool hasFreeNodes() const;
370};
371
372// ============================================================================
373// TEMPLATE AND INLINE FUNCTION DEFINITIONS
374// ============================================================================
375
376 // ------------------
377 // class TreeNodePool
378 // ------------------
379
380// CREATORS
381template <class VALUE, class ALLOCATOR>
382inline
383TreeNodePool<VALUE, ALLOCATOR>::TreeNodePool(const ALLOCATOR& allocator)
384: d_pool(allocator)
385{
386}
387
388template <class VALUE, class ALLOCATOR>
389inline
390TreeNodePool<VALUE, ALLOCATOR>::TreeNodePool(
392: d_pool(MoveUtil::move(MoveUtil::access(original).d_pool))
393{
394}
395
396// MANIPULATORS
397template <class VALUE, class ALLOCATOR>
398inline
399void
400TreeNodePool<VALUE, ALLOCATOR>::adopt(bslmf::MovableRef<TreeNodePool> pool)
401{
402 TreeNodePool& lvalue = pool;
403 d_pool.adopt(MoveUtil::move(lvalue.d_pool));
404}
405
406template <class VALUE, class ALLOCATOR>
407inline
408typename SimplePool<TreeNode<VALUE>, ALLOCATOR>::AllocatorType&
409TreeNodePool<VALUE, ALLOCATOR>::allocator()
410{
411 return d_pool.allocator();
412}
413
414template <class VALUE, class ALLOCATOR>
415inline
416bslalg::RbTreeNode *TreeNodePool<VALUE, ALLOCATOR>::cloneNode(
417 const bslalg::RbTreeNode& original)
418{
419 return emplaceIntoNewNode(
420 static_cast<const TreeNode<VALUE>&>(original).value());
421}
422
423#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
424// {{{ BEGIN GENERATED CODE
425// Command line: sim_cpp11_features.pl bslstl_treenodepool.h
426#ifndef BSLSTL_TREENODEPOOL_VARIADIC_LIMIT
427#define BSLSTL_TREENODEPOOL_VARIADIC_LIMIT 10
428#endif
429#ifndef BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B
430#define BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B BSLSTL_TREENODEPOOL_VARIADIC_LIMIT
431#endif
432#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 0
433template <class VALUE, class ALLOCATOR>
434inline
436TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
437 )
438{
439 TreeNode<VALUE> *node = d_pool.allocate();
440 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
441
442 AllocatorTraits::construct(allocator(),
443 BSLS_UTIL_ADDRESSOF(node->value()));
444 proctor.release();
445 return node;
446}
447#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 0
448
449#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 1
450template <class VALUE, class ALLOCATOR>
451template <class Args_01>
452inline
454TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
455 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01)
456{
457 TreeNode<VALUE> *node = d_pool.allocate();
458 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
459
460 AllocatorTraits::construct(allocator(),
461 BSLS_UTIL_ADDRESSOF(node->value()),
462 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01));
463 proctor.release();
464 return node;
465}
466#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 1
467
468#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 2
469template <class VALUE, class ALLOCATOR>
470template <class Args_01,
471 class Args_02>
472inline
474TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
475 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
476 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02)
477{
478 TreeNode<VALUE> *node = d_pool.allocate();
479 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
480
481 AllocatorTraits::construct(allocator(),
482 BSLS_UTIL_ADDRESSOF(node->value()),
483 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
484 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02));
485 proctor.release();
486 return node;
487}
488#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 2
489
490#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 3
491template <class VALUE, class ALLOCATOR>
492template <class Args_01,
493 class Args_02,
494 class Args_03>
495inline
497TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
498 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
499 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
500 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03)
501{
502 TreeNode<VALUE> *node = d_pool.allocate();
503 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
504
505 AllocatorTraits::construct(allocator(),
506 BSLS_UTIL_ADDRESSOF(node->value()),
507 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
508 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
509 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03));
510 proctor.release();
511 return node;
512}
513#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 3
514
515#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 4
516template <class VALUE, class ALLOCATOR>
517template <class Args_01,
518 class Args_02,
519 class Args_03,
520 class Args_04>
521inline
523TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
524 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
525 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
526 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
527 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04)
528{
529 TreeNode<VALUE> *node = d_pool.allocate();
530 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
531
532 AllocatorTraits::construct(allocator(),
533 BSLS_UTIL_ADDRESSOF(node->value()),
534 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
535 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
536 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
537 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04));
538 proctor.release();
539 return node;
540}
541#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 4
542
543#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 5
544template <class VALUE, class ALLOCATOR>
545template <class Args_01,
546 class Args_02,
547 class Args_03,
548 class Args_04,
549 class Args_05>
550inline
552TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
553 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
554 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
555 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
556 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
557 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05)
558{
559 TreeNode<VALUE> *node = d_pool.allocate();
560 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
561
562 AllocatorTraits::construct(allocator(),
563 BSLS_UTIL_ADDRESSOF(node->value()),
564 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
565 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
566 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
567 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
568 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05));
569 proctor.release();
570 return node;
571}
572#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 5
573
574#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 6
575template <class VALUE, class ALLOCATOR>
576template <class Args_01,
577 class Args_02,
578 class Args_03,
579 class Args_04,
580 class Args_05,
581 class Args_06>
582inline
584TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
585 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
586 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
587 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
588 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
589 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
590 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06)
591{
592 TreeNode<VALUE> *node = d_pool.allocate();
593 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
594
595 AllocatorTraits::construct(allocator(),
596 BSLS_UTIL_ADDRESSOF(node->value()),
597 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
598 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
599 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
600 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
601 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
602 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06));
603 proctor.release();
604 return node;
605}
606#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 6
607
608#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 7
609template <class VALUE, class ALLOCATOR>
610template <class Args_01,
611 class Args_02,
612 class Args_03,
613 class Args_04,
614 class Args_05,
615 class Args_06,
616 class Args_07>
617inline
619TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
620 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
621 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
622 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
623 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
624 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
625 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
626 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07)
627{
628 TreeNode<VALUE> *node = d_pool.allocate();
629 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
630
631 AllocatorTraits::construct(allocator(),
632 BSLS_UTIL_ADDRESSOF(node->value()),
633 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
634 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
635 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
636 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
637 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
638 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06),
639 BSLS_COMPILERFEATURES_FORWARD(Args_07,args_07));
640 proctor.release();
641 return node;
642}
643#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 7
644
645#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 8
646template <class VALUE, class ALLOCATOR>
647template <class Args_01,
648 class Args_02,
649 class Args_03,
650 class Args_04,
651 class Args_05,
652 class Args_06,
653 class Args_07,
654 class Args_08>
655inline
657TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
658 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
659 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
660 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
661 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
662 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
663 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
664 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
665 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08)
666{
667 TreeNode<VALUE> *node = d_pool.allocate();
668 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
669
670 AllocatorTraits::construct(allocator(),
671 BSLS_UTIL_ADDRESSOF(node->value()),
672 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
673 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
674 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
675 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
676 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
677 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06),
678 BSLS_COMPILERFEATURES_FORWARD(Args_07,args_07),
679 BSLS_COMPILERFEATURES_FORWARD(Args_08,args_08));
680 proctor.release();
681 return node;
682}
683#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 8
684
685#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 9
686template <class VALUE, class ALLOCATOR>
687template <class Args_01,
688 class Args_02,
689 class Args_03,
690 class Args_04,
691 class Args_05,
692 class Args_06,
693 class Args_07,
694 class Args_08,
695 class Args_09>
696inline
698TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
699 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
700 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
701 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
702 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
703 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
704 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
705 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
706 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08,
707 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) args_09)
708{
709 TreeNode<VALUE> *node = d_pool.allocate();
710 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
711
712 AllocatorTraits::construct(allocator(),
713 BSLS_UTIL_ADDRESSOF(node->value()),
714 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
715 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
716 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
717 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
718 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
719 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06),
720 BSLS_COMPILERFEATURES_FORWARD(Args_07,args_07),
721 BSLS_COMPILERFEATURES_FORWARD(Args_08,args_08),
722 BSLS_COMPILERFEATURES_FORWARD(Args_09,args_09));
723 proctor.release();
724 return node;
725}
726#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 9
727
728#if BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 10
729template <class VALUE, class ALLOCATOR>
730template <class Args_01,
731 class Args_02,
732 class Args_03,
733 class Args_04,
734 class Args_05,
735 class Args_06,
736 class Args_07,
737 class Args_08,
738 class Args_09,
739 class Args_10>
740inline
742TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
743 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) args_01,
744 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) args_02,
745 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) args_03,
746 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) args_04,
747 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) args_05,
748 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) args_06,
749 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) args_07,
750 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) args_08,
751 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) args_09,
752 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) args_10)
753{
754 TreeNode<VALUE> *node = d_pool.allocate();
755 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
756
757 AllocatorTraits::construct(allocator(),
758 BSLS_UTIL_ADDRESSOF(node->value()),
759 BSLS_COMPILERFEATURES_FORWARD(Args_01,args_01),
760 BSLS_COMPILERFEATURES_FORWARD(Args_02,args_02),
761 BSLS_COMPILERFEATURES_FORWARD(Args_03,args_03),
762 BSLS_COMPILERFEATURES_FORWARD(Args_04,args_04),
763 BSLS_COMPILERFEATURES_FORWARD(Args_05,args_05),
764 BSLS_COMPILERFEATURES_FORWARD(Args_06,args_06),
765 BSLS_COMPILERFEATURES_FORWARD(Args_07,args_07),
766 BSLS_COMPILERFEATURES_FORWARD(Args_08,args_08),
767 BSLS_COMPILERFEATURES_FORWARD(Args_09,args_09),
768 BSLS_COMPILERFEATURES_FORWARD(Args_10,args_10));
769 proctor.release();
770 return node;
771}
772#endif // BSLSTL_TREENODEPOOL_VARIADIC_LIMIT_B >= 10
773
774#else
775// The generated code below is a workaround for the absence of perfect
776// forwarding in some compilers.
777template <class VALUE, class ALLOCATOR>
778template <class... Args>
779inline
781TreeNodePool<VALUE, ALLOCATOR>::emplaceIntoNewNode(
783{
784 TreeNode<VALUE> *node = d_pool.allocate();
785 bslma::DeallocatorProctor<Pool> proctor(node, &d_pool);
786
787 AllocatorTraits::construct(allocator(),
788 BSLS_UTIL_ADDRESSOF(node->value()),
789 BSLS_COMPILERFEATURES_FORWARD(Args,args)...);
790 proctor.release();
791 return node;
792}
793// }}} END GENERATED CODE
794#endif
795
796template <class VALUE, class ALLOCATOR>
797inline
798void TreeNodePool<VALUE, ALLOCATOR>::deleteNode(bslalg::RbTreeNode *node)
799{
800 BSLS_ASSERT(node);
801
802 TreeNode<VALUE> *treeNode = static_cast<TreeNode<VALUE> *>(node);
803 AllocatorTraits::destroy(allocator(),
804 BSLS_UTIL_ADDRESSOF(treeNode->value()));
805 d_pool.deallocate(treeNode);
806}
807
808template <class VALUE, class ALLOCATOR>
809inline
811TreeNodePool<VALUE, ALLOCATOR>::moveIntoNewNode(bslalg::RbTreeNode *original)
812{
813 return emplaceIntoNewNode(
814 MoveUtil::move(static_cast<TreeNode<VALUE> *>(original)->value()));
815}
816
817template <class VALUE, class ALLOCATOR>
818inline
819void TreeNodePool<VALUE, ALLOCATOR>::reserveNodes(size_type numNodes)
820{
821 BSLS_ASSERT_SAFE(0 < numNodes);
822
823 d_pool.reserve(numNodes);
824}
825
826template <class VALUE, class ALLOCATOR>
827inline
828void TreeNodePool<VALUE, ALLOCATOR>::swap(
829 TreeNodePool<VALUE, ALLOCATOR>& other)
830{
831 BSLS_ASSERT_SAFE(allocator() == other.allocator());
832
833 d_pool.swap(other.d_pool);
834}
835
836template <class VALUE, class ALLOCATOR>
837inline
838void TreeNodePool<VALUE, ALLOCATOR>::swapExchangeAllocators(
839 TreeNodePool<VALUE, ALLOCATOR>& other)
840{
841 d_pool.quickSwapExchangeAllocators(other.d_pool);
842}
843
844template <class VALUE, class ALLOCATOR>
845inline
846void TreeNodePool<VALUE, ALLOCATOR>::swapRetainAllocators(
847 TreeNodePool<VALUE, ALLOCATOR>& other)
848{
849 BSLS_ASSERT_SAFE(allocator() == other.allocator());
850
851 d_pool.quickSwapRetainAllocators(other.d_pool);
852}
853
854// ACCESSORS
855template <class VALUE, class ALLOCATOR>
856inline
857const typename SimplePool<TreeNode<VALUE>, ALLOCATOR>::AllocatorType&
858TreeNodePool<VALUE, ALLOCATOR>::allocator() const
859{
860 return d_pool.allocator();
861}
862
863template <class VALUE, class ALLOCATOR>
864inline
865bool TreeNodePool<VALUE, ALLOCATOR>::hasFreeNodes() const
866{
867 return d_pool.hasFreeBlocks();
868}
869
870} // close package namespace
871
872
873#else // if ! defined(DEFINED_BSLSTL_TREENODEPOOL_H)
874# error Not valid except when included from bslstl_treenodepool.h
875#endif // ! defined(COMPILING_BSLSTL_TREENODEPOOL_H)
876
877#endif // ! defined(INCLUDED_BSLSTL_TREENODEPOOL_CPP03)
878
879// ----------------------------------------------------------------------------
880// Copyright 2019 Bloomberg Finance L.P.
881//
882// Licensed under the Apache License, Version 2.0 (the "License");
883// you may not use this file except in compliance with the License.
884// You may obtain a copy of the License at
885//
886// http://www.apache.org/licenses/LICENSE-2.0
887//
888// Unless required by applicable law or agreed to in writing, software
889// distributed under the License is distributed on an "AS IS" BASIS,
890// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
891// See the License for the specific language governing permissions and
892// limitations under the License.
893// ----------------------------- END-OF-FILE ----------------------------------
894
895/** @} */
896/** @} */
897/** @} */
Definition bslalg_rbtreenode.h:376
Definition bslma_deallocatorproctor.h:312
Definition bslmf_movableref.h:751
Types::AllocatorType AllocatorType
Definition bslstl_simplepool.h:341
Types::AllocatorTraits AllocatorTraits
Definition bslstl_simplepool.h:345
void reserveNodes(size_type numNodes)
Definition bslstl_treenodepool.h:510
void adopt(bslmf::MovableRef< TreeNodePool > pool)
Definition bslstl_treenodepool.h:446
AllocatorTraits::size_type size_type
Alias for the size_type of the allocator defined by SimplePool.
Definition bslstl_treenodepool.h:318
bslalg::RbTreeNode * moveIntoNewNode(bslalg::RbTreeNode *original)
Definition bslstl_treenodepool.h:502
Pool::AllocatorType AllocatorType
Alias for the allocator type defined by SimplePool.
Definition bslstl_treenodepool.h:315
void swap(TreeNodePool &other)
Definition bslstl_treenodepool.h:519
AllocatorType & allocator()
Definition bslstl_treenodepool.h:455
bslalg::RbTreeNode * emplaceIntoNewNode(Args &&... args)
Definition bslstl_treenodepool.h:474
void swapExchangeAllocators(TreeNodePool &other)
Definition bslstl_treenodepool.h:529
void deleteNode(bslalg::RbTreeNode *node)
Definition bslstl_treenodepool.h:489
bool hasFreeNodes() const
Definition bslstl_treenodepool.h:556
bslalg::RbTreeNode * cloneNode(const bslalg::RbTreeNode &original)
Definition bslstl_treenodepool.h:462
void swapRetainAllocators(TreeNodePool &other)
Definition bslstl_treenodepool.h:537
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2012
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2018
#define BSLS_UTIL_ADDRESSOF(OBJ)
Definition bsls_util.h:289
Definition bslstl_algorithm.h:82
Definition bslmf_movableref.h:791