BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstp_slist.h
Go to the documentation of this file.
1/// @file bslstp_slist.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstp_slist.h -*-C++-*-
8#ifndef INCLUDED_BSLSTP_SLIST
9#define INCLUDED_BSLSTP_SLIST
10
11/// @defgroup bslstp_slist bslstp_slist
12/// @brief Provide a singly linked list container.
13/// @addtogroup bsl
14/// @{
15/// @addtogroup bslstp
16/// @{
17/// @addtogroup bslstp_slist
18/// @{
19///
20/// <h1> Outline </h1>
21/// * <a href="#bslstp_slist-purpose"> Purpose</a>
22/// * <a href="#bslstp_slist-classes"> Classes </a>
23/// * <a href="#bslstp_slist-description"> Description </a>
24/// * <a href="#bslstp_slist-usage"> Usage </a>
25///
26/// # Purpose {#bslstp_slist-purpose}
27/// Provide a singly linked list container.
28///
29/// @deprecated Do not use directly.
30///
31/// # Classes {#bslstp_slist-classes}
32///
33/// - slist: singly linked list
34///
35/// @see bsl_slist
36///
37/// # Description {#bslstp_slist-description}
38/// This component is for internal use only.
39///
40/// Note that the functions in this component are based on STLPort's
41/// implementation, with copyright notice as follows:
42/// @code
43/// /*
44/// * Copyright (c) 1997
45/// * Silicon Graphics Computer Systems, Inc.
46/// *
47/// * Permission to use, copy, modify, distribute and sell this software
48/// * and its documentation for any purpose is hereby granted without fee,
49/// * provided that the above copyright notice appear in all copies and
50/// * that both that copyright notice and this permission notice appear
51/// * in supporting documentation. Silicon Graphics makes no
52/// * representations about the suitability of this software for any
53/// * purpose. It is provided "as is" without express or implied warranty.
54/// *
55/// */
56///
57/// // Contents originally from stl/_slist.h
58///
59/// /*
60/// *
61/// * Copyright (c) 1996,1997
62/// * Silicon Graphics Computer Systems, Inc.
63/// *
64/// * Copyright (c) 1997
65/// * Moscow Center for SPARC Technology
66/// *
67/// * Copyright (c) 1999
68/// * Boris Fomitchev
69/// *
70/// * This material is provided "as is", with absolutely no warranty expressed
71/// * or implied. Any use is at your own risk.
72/// *
73/// * Permission to use or copy this software for any purpose is hereby granted
74/// * without fee, provided the above notices are retained on all copies.
75/// * Permission to modify the code and to distribute modified code is granted,
76/// * provided the above notices are retained, and a notice that the code was
77/// * modified is included with the above copyright notice.
78/// *
79/// */
80/// @endcode
81///
82/// ## Usage {#bslstp_slist-usage}
83///
84///
85/// This component is for internal use only.
86/// @}
87/** @} */
88/** @} */
89
90/** @addtogroup bsl
91 * @{
92 */
93/** @addtogroup bslstp
94 * @{
95 */
96/** @addtogroup bslstp_slist
97 * @{
98 */
99
100#ifdef BDE_OPENSOURCE_PUBLICATION // STP
101#error "bslstp_slist is not for publication"
102#endif
103#include <bslscm_version.h>
104
105#include <bslstp_alloc.h>
106#include <bslstp_iterator.h>
107#include <bslstp_slistbase.h>
108#include <bslstp_util.h>
109
112
113#include <bslma_autodestructor.h>
116#include <bslma_bslallocator.h>
117
118#include <bslmf_isfundamental.h>
120
121#include <bsls_exceptionutil.h>
122#include <bsls_objectbuffer.h>
123
124
125#include <bsls_util.h>
126
127#include <algorithm>
128
129#include <iterator>
130
131#include <cstddef>
132
133//# undef slist
134//# define slist __WORKAROUND_DBG_RENAME(slist)
135
136//_STLP_BEGIN_NAMESPACE
137namespace bsl {
138
139template <class _Tp>
141{
143};
144
146
147 typedef std::size_t size_type;
148 typedef std::ptrdiff_t difference_type;
149 typedef std::forward_iterator_tag iterator_category;
150
152
154
155 void _M_incr() {
156// _STLP_VERBOSE_ASSERT(_M_node != 0, _StlMsg_INVALID_ADVANCE)
158 }
159 bool operator==(const _Slist_iterator_base& __y ) const {
160 return _M_node == __y._M_node;
161 }
162 bool operator!=(const _Slist_iterator_base& __y ) const {
163 return _M_node != __y._M_node;
164 }
165};
166
167
168template <class _Tp, class _Traits>
170{
171 typedef _Tp value_type;
172 typedef typename _Traits::pointer pointer;
173 typedef typename _Traits::reference reference;
174 typedef std::forward_iterator_tag iterator_category;
175 typedef std::size_t size_type;
176 typedef ptrdiff_t difference_type;
177
181
183
187
188 reference operator*() const { return ((_Node*) _M_node)->_M_data; }
189
190 pointer operator -> ( ) const { return & ( operator * ( ) ) ; }
191
193 {
194 _M_incr();
195 return *this;
196 }
198 {
199 _Self __tmp = *this;
200 _M_incr();
201 return __tmp;
202 }
203};
204
205// Base class that encapsulates details of allocators and simplifies EH
206
207template <class _Tp, class _Alloc>
209
212
214 _M_head(__a, _Slist_node_base() ) {
215 _M_head._M_data._M_next = 0;
216 }
218
219protected:
221
223 {
224 _Node* __next = (_Node*) (__pos->_M_next);
225 _Slist_node_base* __next_next = __next->_M_next;
226 __pos->_M_next = __next_next;
227 BloombergLP::bslma::DestructionUtil::destroy(
228 BSLS_UTIL_ADDRESSOF(__next->_M_data));
229 _M_head.allocatorRef().deallocate(__next,1);
230 return __next_next;
231 }
233
234public:
236 //return _STLP_CONVERT_ALLOCATOR((const _M_node_allocator_type&)_M_head, _Tp);
237 return _M_head.get_allocator();
238 }
240};
241
242template <class _Tp, class _Alloc = bsl::allocator<_Tp> >
243class slist : protected _Slist_base<_Tp,_Alloc>
244{
245private:
246 typedef _Slist_base<_Tp,_Alloc> _Base;
247 typedef slist<_Tp,_Alloc> _Self;
248
249 struct QuickSwap;
250 friend struct QuickSwap;
251
252 /// Function object to quickly swap two slists with identical
253 /// allocators and allocation modes.
254 ///
255 /// See @ref bslstp_slist
256 struct QuickSwap {
257
258 /// Swap contents of `v1` and `v2`. Undefined unless
259 /// `v1.get_allocator() == v2.get_allocator()`.
260 void operator()(_Self& v1, _Self& v2) const
261 {
262 // MODIFIED BY ARTHUR
263 //_STLP_STD::swap(v1._M_head._M_data, v2._M_head._M_data);
264 typedef BloombergLP::bslalg::ScalarPrimitives primitive;
265 primitive::swap(v1._M_head._M_data, v2._M_head._M_data);
266 }
267 };
268
269public:
270 typedef _Tp value_type;
272 typedef const value_type* const_pointer;
275 typedef std::size_t size_type;
276 typedef std::ptrdiff_t difference_type;
277 typedef std::forward_iterator_tag _Iterator_category;
278
281
282 typedef typename _Base::allocator_type allocator_type;
283
284
285private:
286 typedef _Slist_node<_Tp> _Node;
289
290 _Node* _M_create_node(const value_type& __x = _Tp()) {
291 _Node* __node = this->_M_head.allocatorRef().allocate(1);
292 BSLS_TRY {
293 typedef BloombergLP::bslma::ConstructionUtil Util;
294 Util::construct(BSLS_UTIL_ADDRESSOF(__node->_M_data),
295 this->get_allocator(),
296 __x);
297 __node->_M_next = 0;
298 }
299 BSLS_CATCH(...) {
300 this->_M_head.allocatorRef().deallocate(__node, 1);
302 }
303 return __node;
304 }
305
306public:
307 allocator_type get_allocator() const { return _Base::get_allocator(); }
308
309 explicit slist(const allocator_type& __a = allocator_type()) : _Slist_base<_Tp,_Alloc>(__a) {}
310
311 explicit slist(size_type __n, const value_type& __x = _Tp(),
312 const allocator_type& __a = allocator_type())
313 : _Slist_base<_Tp,_Alloc>(__a)
314 { _M_insert_after_fill(&this->_M_head._M_data, __n, __x); }
315
316
317 // We don't need any dispatching tricks here, because _M_insert_after_range
318 // already does them.
319 template <class _InputIterator>
320 slist(_InputIterator __first, _InputIterator __last,
321 const allocator_type& __a = allocator_type()) :
322 _Slist_base<_Tp,_Alloc>(__a)
323 { _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
324
325 slist(const _Self& __x)
326 : _Slist_base<_Tp, _Alloc>(BloombergLP::bslstp::Util::copyContainerAllocator(__x.get_allocator()))
327 { insert(begin(), __x.begin(), __x.end()); }
328
329 // Copy-construct with alternative allocator.
330 slist(const _Self& __x, const allocator_type& __a)
331 : _Slist_base<_Tp, _Alloc>(__a)
332 { insert(begin(), __x.begin(), __x.end()); }
333
334 /*explicit slist(__full_move_source<_Self> src)
335 : _Slist_base<_Tp, _Alloc>(_FullMoveSource<_Slist_base<_Tp, _Alloc> >(src.get())) {
336 }*/
337
338// explicit slist(__partial_move_source<_Self> src)
339// : _Slist_base<_Tp, _Alloc>(src.get()) {
340// src.get()._M_head._M_data._M_next = 0;
341// }
342
343 _Self& operator= (const _Self& __x);
344
346
347public:
348 // assign(), a generalized assignment member function. Two
349 // versions: one that takes a count, and one that takes a range.
350 // The range version is a member template, so we dispatch on whether
351 // or not the type is an integer.
352
353 void assign(size_type __n, const _Tp& __val)
354 { _M_fill_assign(__n, __val); }
355
356 void _M_fill_assign(size_type __n, const _Tp& __val);
357
358 template <class _InputIterator>
359 void assign(_InputIterator __first, _InputIterator __last) {
360
361 // SIMPLIFIED BY ALISDAIR
363 }
364
365 template <class _Integer>
366 void _M_assign_dispatch(_Integer __n, _Integer __val, bsl::true_type *)
367 { _M_fill_assign((size_type) __n, (_Tp) __val); }
368
369 template <class _InputIter>
370 void
371 _M_assign_dispatch(_InputIter __first, _InputIter __last, bsl::false_type *) {
372 _Node_base* __prev = &this->_M_head._M_data;
373 _Node* __node = (_Node*) this->_M_head._M_data._M_next;
374 while (__node != 0 && __first != __last) {
375 __node->_M_data = *__first;
376 __prev = __node;
377 __node = (_Node*) __node->_M_next;
378 ++__first;
379 }
380 if (__first != __last)
381 _M_insert_after_range(__prev, __first, __last);
382 else
383 this->_M_erase_after(__prev, 0);
384 }
385
386public:
387
388 // Experimental new feature: before_begin() returns a
389 // non-dereferenceable iterator that, when incremented, yields
390 // begin(). This iterator may be used as the argument to
391 // insert_after, erase_after, etc. Note that even for an empty
392 // slist, before_begin() is not the same iterator as end(). It
393 // is always necessary to increment before_begin() at least once to
394 // obtain end().
395 iterator before_begin() { return iterator((_Node*) &this->_M_head._M_data); }
396 const_iterator before_begin() const
397 { return const_iterator((_Node*) &this->_M_head._M_data); }
398
399 iterator begin() { return iterator((_Node*)this->_M_head._M_data._M_next); }
400 const_iterator begin() const
401 { return const_iterator((_Node*)this->_M_head._M_data._M_next);}
402
403 iterator end() { return iterator(0); }
404 const_iterator end() const { return const_iterator(0); }
405
406 size_type size() const { return _Sl_global_inst::size(this->_M_head._M_data._M_next); }
407
408 size_type max_size() const { return size_type(-1); }
409
410 bool empty() const { return this->_M_head._M_data._M_next == 0; }
411
412 void swap(_Self& __x) {
413 BloombergLP::bslstp::Util::swapContainers(*this, __x, QuickSwap());
414 }
415
416public:
417 reference front() { return ((_Node*) this->_M_head._M_data._M_next)->_M_data; }
418 const_reference front() const
419 { return ((_Node*) this->_M_head._M_data._M_next)->_M_data; }
420 void push_front(const value_type& __x = _Tp()) {
421 __slist_make_link(&this->_M_head._M_data, _M_create_node(__x));
422 }
423
424 void pop_front() {
425 _Node* __node = (_Node*) this->_M_head._M_data._M_next;
426 this->_M_head._M_data._M_next = __node->_M_next;
427 BloombergLP::bslma::DestructionUtil::destroy(
428 BSLS_UTIL_ADDRESSOF(__node->_M_data));
429 this->_M_head.allocatorRef().deallocate(__node, 1);
430 }
431
433 return iterator((_Node*) _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node));
434 }
436 return const_iterator((_Node*) _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node));
437 }
438
439private:
440 _Node* _M_insert_after(_Node_base* __pos, const value_type& __x = _Tp()) {
441 return (_Node*) (__slist_make_link(__pos, _M_create_node(__x)));
442 }
443
444
445 void _M_insert_after_fill(_Node_base *__pos,
446 size_type __n, const value_type& __x) {
447 for (size_type __i = 0; __i < __n; ++__i)
448 __pos = __slist_make_link(__pos, _M_create_node(__x));
449 }
450
451 // Check whether it's an integral type. If so, it's not an iterator.
452 template <class _InIter>
453 void _M_insert_after_range(_Node_base *__pos,
454 _InIter __first, _InIter __last) {
455 // SIMPLIFIED BY ALISDAIR
456 _M_insert_after_range(__pos, __first, __last, (bsl::is_fundamental<_InIter> *) 0);
457 }
458
459 template <class _Integer>
460 void _M_insert_after_range(_Node_base* __pos, _Integer __n, _Integer __x,
461 bsl::true_type *) {
462 _M_insert_after_fill(__pos, __n, __x);
463 }
464
465 template <class _InIter>
466 void _M_insert_after_range(_Node_base *__pos,
467 _InIter __first, _InIter __last,
468 bsl::false_type *) {
469 while (__first != __last) {
470 __pos = __slist_make_link(__pos, _M_create_node(*__first));
471 ++__first;
472 }
473 }
474
475
476public:
477
478 iterator insert_after(iterator __pos, const value_type& __x = _Tp()) {
479 return iterator(_M_insert_after(__pos._M_node, __x));
480 }
481
482
483 void insert_after(iterator __pos, size_type __n, const value_type& __x) {
484 _M_insert_after_fill(__pos._M_node, __n, __x);
485 }
486
487 // We don't need any dispatching tricks here, because _M_insert_after_range
488 // already does them.
489 template <class _InIter>
490 void insert_after(iterator __pos, _InIter __first, _InIter __last) {
491 _M_insert_after_range(__pos._M_node, __first, __last);
492 }
493
494
495 iterator insert(iterator __pos, const value_type& __x = _Tp()) {
496 return iterator(_M_insert_after(
497 _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
498 __x));
499 }
500
501
502 void insert(iterator __pos, size_type __n, const value_type& __x) {
503 _M_insert_after_fill(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), __n, __x);
504 }
505
506 // We don't need any dispatching tricks here, because _M_insert_after_range
507 // already does them.
508 template <class _InIter>
509 void insert(iterator __pos, _InIter __first, _InIter __last) {
510 _M_insert_after_range(
511 _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
512 __first, __last);
513 }
514
515
516
517public:
519 return iterator((_Node*) this->_M_erase_after(__pos._M_node));
520 }
521 iterator erase_after(iterator __before_first, iterator __last) {
522 return iterator((_Node*) this->_M_erase_after(__before_first._M_node,
523 __last._M_node));
524 }
525
527 return iterator((_Node*) this->_M_erase_after(_Sl_global_inst::__previous(
528 &this->_M_head._M_data,
529 __pos._M_node)));
530 }
531 iterator erase(iterator __first, iterator __last) {
532 return iterator((_Node*) this->_M_erase_after(
533 _Sl_global_inst::__previous(&this->_M_head._M_data, __first._M_node), __last._M_node));
534 }
535
536 void resize(size_type new_size, const value_type& __x = _Tp());
537
538 void clear() {
539 this->_M_erase_after(&this->_M_head._M_data, 0);
540 }
541
542public:
543 // Moves the range [__before_first + 1, __before_last + 1) to *this,
544 // inserting it immediately after __pos. This is constant time.
545 void splice_after(iterator __pos,
546 iterator __before_first, iterator __before_last)
547 {
548 if (__before_first != __before_last) {
549 _Sl_global_inst::__splice_after(__pos._M_node, __before_first._M_node,
550 __before_last._M_node);
551 }
552 }
553
554 // Moves the element that follows __prev to *this, inserting it immediately
555 // after __pos. This is constant time.
556 void splice_after(iterator __pos, iterator __prev)
557 {
558 _Sl_global_inst::__splice_after(__pos._M_node,
559 __prev._M_node, __prev._M_node->_M_next);
560 }
561
562 // Removes all of the elements from the list __x to *this, inserting
563 // them immediately after __pos. __x must not be *this. Complexity:
564 // linear in __x.size().
565 void splice_after(iterator __pos, _Self& __x)
566 {
567 _Sl_global_inst::__splice_after(__pos._M_node, &__x._M_head._M_data);
568 }
569
570 // Linear in distance(begin(), __pos), and linear in __x.size().
571 void splice(iterator __pos, _Self& __x) {
572 if (__x._M_head._M_data._M_next)
573 _Sl_global_inst::__splice_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
574 &__x._M_head._M_data, _Sl_global_inst::__previous(&__x._M_head._M_data, 0));
575 }
576
577 // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i).
578 void splice(iterator __pos, _Self& __x, iterator __i) {
579 _Sl_global_inst::__splice_after(
580 _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
581 _Sl_global_inst::__previous(&__x._M_head._M_data, __i._M_node),
582 __i._M_node);
583 }
584
585 // Linear in distance(begin(), __pos), in distance(__x.begin(), __first),
586 // and in distance(__first, __last).
587 void splice(iterator __pos, _Self& __x, iterator __first, iterator __last)
588 {
589 if (__first != __last)
590 _Sl_global_inst::__splice_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
591 _Sl_global_inst::__previous(&__x._M_head._M_data, __first._M_node),
592 _Sl_global_inst::__previous(__first._M_node, __last._M_node));
593 }
594
595public:
596 void reverse() {
597 if (this->_M_head._M_data._M_next)
598 this->_M_head._M_data._M_next = _Sl_global_inst::__reverse(this->_M_head._M_data._M_next);
599 }
600
601 void remove(const _Tp& __val);
602 void unique();
603 void merge(_Self& __x);
604 void sort();
605
606 template <class _Predicate>
607 void remove_if(_Predicate __pred) {
608 _Node_base* __cur = &this->_M_head._M_data;
609 while (__cur->_M_next) {
610 if (__pred(((_Node*) __cur->_M_next)->_M_data))
611 this->_M_erase_after(__cur);
612 else
613 __cur = __cur->_M_next;
614 }
615 }
616
617 template <class _BinaryPredicate>
618 void unique(_BinaryPredicate __pred) {
619 _Node* __cur = (_Node*) this->_M_head._M_data._M_next;
620 if (__cur) {
621 while (__cur->_M_next) {
622 if (__pred(((_Node*)__cur)->_M_data,
623 ((_Node*)(__cur->_M_next))->_M_data))
624 this->_M_erase_after(__cur);
625 else
626 __cur = (_Node*) __cur->_M_next;
627 }
628 }
629 }
630
631 template <class _StrictWeakOrdering>
633 _StrictWeakOrdering __comp) {
634 _Node_base* __n1 = &this->_M_head._M_data;
635 while (__n1->_M_next && __x._M_head._M_data._M_next) {
636 if (__comp(((_Node*) __x._M_head._M_data._M_next)->_M_data,
637 ((_Node*) __n1->_M_next)->_M_data))
638 _Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
639 __n1 = __n1->_M_next;
640 }
641 if (__x._M_head._M_data._M_next) {
642 __n1->_M_next = __x._M_head._M_data._M_next;
643 __x._M_head._M_data._M_next = 0;
644 }
645 }
646
647 template <class _StrictWeakOrdering>
648 void sort(_StrictWeakOrdering __comp) {
649 if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
650 _Self __carry(this->get_allocator());
651
652 // Create an array of 64 '_Self' objects. Since we cannot pass
653 // constructor arguments to array element constructors, we instead use
654 // an array of raw memory objects ('bsls::ObjectBuffer') and initialize
655 // them with the desired allocator as a separate step. After
656 // initialization, we ensure that destructors are called by creating an
657 // auto-destructor object.
658 BloombergLP::bsls::ObjectBuffer<_Self> __counterBuffers[64];
659 _Self* __counter = &__counterBuffers[0].object();
660 BloombergLP::bslalg::ArrayPrimitives::uninitializedFillN(
661 __counter, 64, __carry,
662 this->_M_head.get_allocator());
663 BloombergLP::bslma::AutoDestructor<_Self> __counterGuard(__counter, 64);
664
665 int __fill = 0;
666 while (!empty()) {
667 _Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
668 int __i = 0;
669 while (__i < __fill && !__counter[__i].empty()) {
670 __counter[__i].merge(__carry, __comp);
671 __carry.swap(__counter[__i]);
672 ++__i;
673 }
674 __carry.swap(__counter[__i]);
675 if (__i == __fill)
676 ++__fill;
677 }
678
679 for (int __i = 1; __i < __fill; ++__i)
680 __counter[__i].merge(__counter[__i-1], __comp);
681 this->swap(__counter[__fill-1]);
682 }
683 }
684
685};
686
687template <class _Tp, class _Alloc>
688inline
689bool operator==(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2)
690{
691 typedef typename slist<_Tp,_Alloc>::const_iterator const_iterator;
692 const_iterator __end1 = _SL1.end();
693 const_iterator __end2 = _SL2.end();
694
695 const_iterator __i1 = _SL1.begin();
696 const_iterator __i2 = _SL2.begin();
697 while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
698 ++__i1;
699 ++__i2;
700 }
701 return __i1 == __end1 && __i2 == __end2;
702}
703
704template <class _Tp, class _Alloc>
705inline
706bool operator<(const slist<_Tp, _Alloc>& __x,
707 const slist<_Tp, _Alloc>& __y) {
708 return std::lexicographical_compare(__x.begin(), __x.end(),
709 __y.begin(), __y.end());
710}
711
712template <class _Tp, class _Alloc>
713inline
714bool operator!=(const slist<_Tp, _Alloc>& __x,
715 const slist<_Tp, _Alloc>& __y) {return !(__x == __y);}
716
717template <class _Tp, class _Alloc>
718inline
719bool operator>(const slist<_Tp, _Alloc>& __x,
720 const slist<_Tp, _Alloc>& __y) {return __y < __x;}
721
722template <class _Tp, class _Alloc>
723inline
724bool operator<=(const slist<_Tp, _Alloc>& __x,
725 const slist<_Tp, _Alloc>& __y) { return !(__y < __x);}
726
727template <class _Tp, class _Alloc>
728inline
729bool operator>=(const slist<_Tp, _Alloc>& __x,
730 const slist<_Tp, _Alloc>& __y) { return !(__x < __y);}
731
732//template <class _Tp, class _Alloc>
733//struct __partial_move_traits<slist<_Tp, _Alloc> > {
734// typedef __true_type supported;
735//};
736//
737//template <class _Tp, class _Alloc>
738//struct __action_on_move<slist<_Tp, _Alloc> > {
739// typedef __true_type swap;
740//};
741
742//# define _STLP_EQUAL_OPERATOR_SPECIALIZED
743//# define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
744//# define _STLP_TEMPLATE_CONTAINER slist<_Tp, _Alloc>
745//# include <bslstp_stl_relops_cont.h>
746//# undef _STLP_TEMPLATE_CONTAINER
747//# undef _STLP_TEMPLATE_HEADER
748//# undef _STLP_EQUAL_OPERATOR_SPECIALIZED
749
750} // close namespace bsl
751
752// BEGIN FORMER CONTENTS OF bslstp_stl_slist.c
753/*
754 *
755 * Copyright (c) 1996,1997
756 * Silicon Graphics Computer Systems, Inc.
757 *
758 * Copyright (c) 1999
759 * Boris Fomitchev
760 *
761 * This material is provided "as is", with absolutely no warranty expressed
762 * or implied. Any use is at your own risk.
763 *
764 * Permission to use or copy this software for any purpose is hereby granted
765 * without fee, provided the above notices are retained on all copies.
766 * Permission to modify the code and to distribute modified code is granted,
767 * provided the above notices are retained, and a notice that the code was
768 * modified is included with the above copyright notice.
769 *
770 */
771
772// #ifndef INCLUDED_BSLSTP_STL_SLIST
773// # include <bslstp_stl_slist.h>
774// #endif
775
776namespace bsl {
777
778template <class _Tp, class _Alloc>
779_Slist_node_base*
781 _Slist_node_base* __last_node) {
782 _Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next);
783 while (__cur != __last_node) {
784 _Slist_node<_Tp>* __tmp = __cur;
785 __cur = (_Slist_node<_Tp>*) __cur->_M_next;
786 BloombergLP::bslma::DestructionUtil::destroy(
788 _M_head.allocatorRef().deallocate(__tmp,1);
789 }
790 __before_first->_M_next = __last_node;
791 return __last_node;
792}
793
794template <class _Tp, class _Alloc>
796{
797 if (&__x != this) {
798 _Node_base* __p1 = &this->_M_head._M_data;
799 _Node* __n1 = (_Node*) this->_M_head._M_data._M_next;
800 const _Node* __n2 = (const _Node*) __x._M_head._M_data._M_next;
801 while (__n1 && __n2) {
802 __n1->_M_data = __n2->_M_data;
803 __p1 = __n1;
804 __n1 = (_Node*) __n1->_M_next;
805 __n2 = (const _Node*) __n2->_M_next;
806 }
807 if (__n2 == 0)
808 this->_M_erase_after(__p1, 0);
809 else
810 _M_insert_after_range(__p1, const_iterator(const_cast<_Node*>(__n2)),
811 const_iterator(0));
812 }
813 return *this;
814}
815
816template <class _Tp, class _Alloc>
818 _Node_base* __prev = &this->_M_head._M_data;
819 _Node* __node = (_Node*) this->_M_head._M_data._M_next;
820 for ( ; __node != 0 && __n > 0 ; --__n) {
821 __node->_M_data = __val;
822 __prev = __node;
823 __node = (_Node*) __node->_M_next;
824 }
825 if (__n > 0)
826 _M_insert_after_fill(__prev, __n, __val);
827 else
828 this->_M_erase_after(__prev, 0);
829}
830
831
832template <class _Tp, class _Alloc>
833void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
834{
835 _Node_base* __cur = &this->_M_head._M_data;
836 while (__cur->_M_next != 0 && __len > 0) {
837 --__len;
838 __cur = __cur->_M_next;
839 }
840 if (__cur->_M_next)
841 this->_M_erase_after(__cur, 0);
842 else
843 _M_insert_after_fill(__cur, __len, __x);
844}
845
846template <class _Tp, class _Alloc>
847void slist<_Tp,_Alloc>::remove(const _Tp& __val)
848{
849 _Node_base* __cur = &this->_M_head._M_data;
850 while (__cur && __cur->_M_next) {
851 if (((_Node*) __cur->_M_next)->_M_data == __val)
852 this->_M_erase_after(__cur);
853 else
854 __cur = __cur->_M_next;
855 }
856}
857
858template <class _Tp, class _Alloc>
860{
861 _Node_base* __cur = this->_M_head._M_data._M_next;
862 if (__cur) {
863 while (__cur->_M_next) {
864 if (((_Node*)__cur)->_M_data ==
865 ((_Node*)(__cur->_M_next))->_M_data)
866 this->_M_erase_after(__cur);
867 else
868 __cur = __cur->_M_next;
869 }
870 }
871}
872
873template <class _Tp, class _Alloc>
875{
876 _Node_base* __n1 = &this->_M_head._M_data;
877 while (__n1->_M_next && __x._M_head._M_data._M_next) {
878 if (((_Node*) __x._M_head._M_data._M_next)->_M_data <
879 ((_Node*) __n1->_M_next)->_M_data)
880 _Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
881 __n1 = __n1->_M_next;
882 }
883 if (__x._M_head._M_data._M_next) {
884 __n1->_M_next = __x._M_head._M_data._M_next;
885 __x._M_head._M_data._M_next = 0;
886 }
887}
888
889template <class _Tp, class _Alloc>
891{
892 if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
893 _Self __carry(this->get_allocator());
894
895 // Create an array of 64 '_Self' objects. Since we cannot pass
896 // constructor arguments to array element constructors, we instead use
897 // an array of raw memory objects ('bsls::ObjectBuffer') and initialize
898 // them with the desired allocator as a separate step. After
899 // initialization, we ensure that destructors are called by creating an
900 // auto-destructor object.
901 BloombergLP::bsls::ObjectBuffer<_Self> __counterBuffers[64];
902 _Self* __counter = &__counterBuffers[0].object();
904 this->get_allocator());
905 BloombergLP::bslalg::ArrayPrimitives::uninitializedFillN(
906 __counter, 64, __carry,
907 __alloc);
908 BloombergLP::bslma::AutoDestructor<_Self> __counterGuard(__counter, 64);
909
910 int __fill = 0;
911 while (!empty()) {
912 _Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
913 int __i = 0;
914 while (__i < __fill && !__counter[__i].empty()) {
915 __counter[__i].merge(__carry);
916 __carry.swap(__counter[__i]);
917 ++__i;
918 }
919 __carry.swap(__counter[__i]);
920 if (__i == __fill)
921 ++__fill;
922 }
923
924 for (int __i = 1; __i < __fill; ++__i)
925 __counter[__i].merge(__counter[__i-1]);
926 this->swap(__counter[__fill-1]);
927 }
928}
929
930//# undef slist
931//# undef size_type
932
933} // close namespace bsl
934
935// Local Variables:
936// mode:C++
937// End:
938// END FORMER CONTENTS OF bslstp_stl_slist.c
939
940//# undef slist
941//# define __slist__ __FULL_NAME(slist)
942//
943//#if defined (_STLP_DEBUG)
944//# include <stl/debug/bslstp_stl_slist.h>
945//#endif
946
947namespace std {
948
949// Specialization of insert_iterator so that insertions will be constant
950// time rather than linear time.
951
952
953template <class _Tp, class _Alloc>
954class insert_iterator<bsl::slist<_Tp, _Alloc> > {
955protected:
958 typename _Container::iterator iter;
959public:
961 typedef output_iterator_tag iterator_category;
962 typedef void value_type;
963 typedef void difference_type;
964 typedef void pointer;
965 typedef void reference;
966
967 insert_iterator(_Container& __x, typename _Container::iterator __i)
968 : container(&__x) {
969 if (__i == __x.begin())
970 iter = __x.before_begin();
971 else
972 iter = __x.previous(__i);
973 }
974
975 insert_iterator<_Container>&
976 operator=(const typename _Container::value_type& __val) {
977 iter = container->insert_after(iter, __val);
978 return *this;
979 }
980 insert_iterator<_Container>& operator*() { return *this; }
981 insert_iterator<_Container>& operator++() { return *this; }
982 insert_iterator<_Container>& operator++(int) { return *this; }
983};
984
985
986} // close namespace std
987
988//# if defined ( _STLP_USE_WRAPPER_FOR_ALLOC_PARAM )
989//# include <stl/wrappers/bslstp_stl_slist.h>
990//# endif
991
992//# if (_STLP_OUTERMOST_HEADER_ID == 0x58)
993//# include <bslstp_stl_epilog.h>
994//# undef _STLP_OUTERMOST_HEADER_ID
995//# endif
996
997#endif /* INCLUDED_BSLSTP_SLIST */
998
999// Local Variables:
1000// mode:C++
1001// End:
1002
1003/** @} */
1004/** @} */
1005/** @} */
Definition bslstp_alloc.h:105
Definition bslstp_slist.h:244
void splice(iterator __pos, _Self &__x, iterator __first, iterator __last)
Definition bslstp_slist.h:587
const_reference front() const
Definition bslstp_slist.h:418
void swap(_Self &__x)
Definition bslstp_slist.h:412
value_type & reference
Definition bslstp_slist.h:273
void merge(_Self &__x)
Definition bslstp_slist.h:874
_Tp value_type
Definition bslstp_slist.h:270
void unique()
Definition bslstp_slist.h:859
std::ptrdiff_t difference_type
Definition bslstp_slist.h:276
iterator end()
Definition bslstp_slist.h:403
iterator erase_after(iterator __before_first, iterator __last)
Definition bslstp_slist.h:521
iterator before_begin()
Definition bslstp_slist.h:395
void insert(iterator __pos, size_type __n, const value_type &__x)
Definition bslstp_slist.h:502
void reverse()
Definition bslstp_slist.h:596
void splice_after(iterator __pos, iterator __before_first, iterator __before_last)
Definition bslstp_slist.h:545
void remove_if(_Predicate __pred)
Definition bslstp_slist.h:607
_Self & operator=(const _Self &__x)
Definition bslstp_slist.h:795
const value_type * const_pointer
Definition bslstp_slist.h:272
reference front()
Definition bslstp_slist.h:417
bool empty() const
Definition bslstp_slist.h:410
size_type size() const
Definition bslstp_slist.h:406
iterator begin()
Definition bslstp_slist.h:399
iterator insert(iterator __pos, const value_type &__x=_Tp())
Definition bslstp_slist.h:495
void sort(_StrictWeakOrdering __comp)
Definition bslstp_slist.h:648
void insert_after(iterator __pos, _InIter __first, _InIter __last)
Definition bslstp_slist.h:490
iterator insert_after(iterator __pos, const value_type &__x=_Tp())
Definition bslstp_slist.h:478
slist(const _Self &__x)
Definition bslstp_slist.h:325
const_iterator end() const
Definition bslstp_slist.h:404
void splice_after(iterator __pos, _Self &__x)
Definition bslstp_slist.h:565
iterator erase(iterator __pos)
Definition bslstp_slist.h:526
void _M_fill_assign(size_type __n, const _Tp &__val)
Definition bslstp_slist.h:817
void insert_after(iterator __pos, size_type __n, const value_type &__x)
Definition bslstp_slist.h:483
slist(const allocator_type &__a=allocator_type())
Definition bslstp_slist.h:309
void unique(_BinaryPredicate __pred)
Definition bslstp_slist.h:618
iterator erase(iterator __first, iterator __last)
Definition bslstp_slist.h:531
_Base::allocator_type allocator_type
Definition bslstp_slist.h:282
allocator_type get_allocator() const
Definition bslstp_slist.h:307
slist(size_type __n, const value_type &__x=_Tp(), const allocator_type &__a=allocator_type())
Definition bslstp_slist.h:311
void merge(slist< _Tp, _Alloc > &__x, _StrictWeakOrdering __comp)
Definition bslstp_slist.h:632
const_iterator before_begin() const
Definition bslstp_slist.h:396
iterator previous(const_iterator __pos)
Definition bslstp_slist.h:432
void push_front(const value_type &__x=_Tp())
Definition bslstp_slist.h:420
void splice_after(iterator __pos, iterator __prev)
Definition bslstp_slist.h:556
_Slist_iterator< _Tp, _Nonconst_traits< _Tp > > iterator
Definition bslstp_slist.h:279
void splice(iterator __pos, _Self &__x, iterator __i)
Definition bslstp_slist.h:578
void splice(iterator __pos, _Self &__x)
Definition bslstp_slist.h:571
slist(const _Self &__x, const allocator_type &__a)
Definition bslstp_slist.h:330
void sort()
Definition bslstp_slist.h:890
void insert(iterator __pos, _InIter __first, _InIter __last)
Definition bslstp_slist.h:509
std::forward_iterator_tag _Iterator_category
Definition bslstp_slist.h:277
void _M_assign_dispatch(_InputIter __first, _InputIter __last, bsl::false_type *)
Definition bslstp_slist.h:371
const_iterator begin() const
Definition bslstp_slist.h:400
_Slist_iterator< _Tp, _Const_traits< _Tp > > const_iterator
Definition bslstp_slist.h:280
size_type max_size() const
Definition bslstp_slist.h:408
value_type * pointer
Definition bslstp_slist.h:271
const_iterator previous(const_iterator __pos) const
Definition bslstp_slist.h:435
void resize(size_type new_size, const value_type &__x=_Tp())
Definition bslstp_slist.h:833
void assign(_InputIterator __first, _InputIterator __last)
Definition bslstp_slist.h:359
slist(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Definition bslstp_slist.h:320
friend struct QuickSwap
Definition bslstp_slist.h:250
~slist()
Definition bslstp_slist.h:345
void assign(size_type __n, const _Tp &__val)
Definition bslstp_slist.h:353
const value_type & const_reference
Definition bslstp_slist.h:274
void remove(const _Tp &__val)
Definition bslstp_slist.h:847
void pop_front()
Definition bslstp_slist.h:424
std::size_t size_type
Definition bslstp_slist.h:275
void _M_assign_dispatch(_Integer __n, _Integer __val, bsl::true_type *)
Definition bslstp_slist.h:366
iterator erase_after(iterator __pos)
Definition bslstp_slist.h:518
void clear()
Definition bslstp_slist.h:538
_Container::iterator iter
Definition bslstp_slist.h:958
output_iterator_tag iterator_category
Definition bslstp_slist.h:961
insert_iterator< _Container > & operator++()
Definition bslstp_slist.h:981
void difference_type
Definition bslstp_slist.h:963
_Container * container
Definition bslstp_slist.h:957
bsl::slist< _Tp, _Alloc > _Container
Definition bslstp_slist.h:956
void reference
Definition bslstp_slist.h:965
insert_iterator< _Container > & operator++(int)
Definition bslstp_slist.h:982
_Container container_type
Definition bslstp_slist.h:960
insert_iterator< _Container > & operator=(const typename _Container::value_type &__val)
Definition bslstp_slist.h:976
insert_iterator< _Container > & operator*()
Definition bslstp_slist.h:980
void pointer
Definition bslstp_slist.h:964
insert_iterator(_Container &__x, typename _Container::iterator __i)
Definition bslstp_slist.h:967
void value_type
Definition bslstp_slist.h:962
#define BSLS_CATCH(X)
Definition bsls_exceptionutil.h:372
#define BSLS_TRY
Definition bsls_exceptionutil.h:370
#define BSLS_RETHROW
Definition bsls_exceptionutil.h:378
#define BSLS_UTIL_ADDRESSOF(OBJ)
Definition bsls_util.h:296
Definition bdlat_valuetypefunctions.h:939
_Slist_node_base * __slist_make_link(_Slist_node_base *__prev_node, _Slist_node_base *__new_node)
Definition bslstp_slistbase.h:95
BSLS_KEYWORD_CONSTEXPR bool empty(const CONTAINER &container)
Definition bslstl_iterator.h:1377
Definition bslstp_exfunctional.h:325
Definition bdldfp_decimal.h:5549
_Rebind_type::other allocator_type
Definition bslstp_alloc.h:98
Definition bslstp_slist.h:208
_Slist_node_base * _M_erase_after(_Slist_node_base *, _Slist_node_base *)
Definition bslstp_slist.h:780
_STLP_alloc_proxy< _Slist_node_base, _Node, _M_node_allocator_type > _M_head
Definition bslstp_slist.h:239
_Slist_node_base * _M_erase_after(_Slist_node_base *__pos)
Definition bslstp_slist.h:222
_Alloc_traits< _Tp, _Alloc >::allocator_type allocator_type
Definition bslstp_slist.h:210
~_Slist_base()
Definition bslstp_slist.h:217
_Slist_node< _Tp > _Node
Definition bslstp_slist.h:211
_Alloc_traits< _Node, _Alloc >::allocator_type _M_node_allocator_type
Definition bslstp_slist.h:220
allocator_type get_allocator() const
Definition bslstp_slist.h:235
_Slist_base(const allocator_type &__a)
Definition bslstp_slist.h:213
Definition bslstp_slist.h:145
std::ptrdiff_t difference_type
Definition bslstp_slist.h:148
bool operator!=(const _Slist_iterator_base &__y) const
Definition bslstp_slist.h:162
_Slist_node_base * _M_node
Definition bslstp_slist.h:151
std::forward_iterator_tag iterator_category
Definition bslstp_slist.h:149
std::size_t size_type
Definition bslstp_slist.h:147
void _M_incr()
Definition bslstp_slist.h:155
_Slist_iterator_base(_Slist_node_base *__x)
Definition bslstp_slist.h:153
bool operator==(const _Slist_iterator_base &__y) const
Definition bslstp_slist.h:159
Definition bslstp_slist.h:170
_Traits::pointer pointer
Definition bslstp_slist.h:172
_Slist_node< value_type > _Node
Definition bslstp_slist.h:182
_Slist_iterator< _Tp, _Const_traits< _Tp > > const_iterator
Definition bslstp_slist.h:179
_Slist_iterator(const iterator &__x)
Definition bslstp_slist.h:186
_Slist_iterator< _Tp, _Nonconst_traits< _Tp > > iterator
Definition bslstp_slist.h:178
ptrdiff_t difference_type
Definition bslstp_slist.h:176
_Tp value_type
Definition bslstp_slist.h:171
std::forward_iterator_tag iterator_category
Definition bslstp_slist.h:174
pointer operator->() const
Definition bslstp_slist.h:190
reference operator*() const
Definition bslstp_slist.h:188
_Self operator++(int)
Definition bslstp_slist.h:197
std::size_t size_type
Definition bslstp_slist.h:175
_Slist_iterator(_Node *__x)
Definition bslstp_slist.h:184
_Slist_iterator< _Tp, _Traits > _Self
Definition bslstp_slist.h:180
_Traits::reference reference
Definition bslstp_slist.h:173
_Slist_iterator()
Definition bslstp_slist.h:185
_Self & operator++()
Definition bslstp_slist.h:192
Definition bslstp_slistbase.h:90
_Slist_node_base * _M_next
Definition bslstp_slistbase.h:91
Definition bslstp_slist.h:141
_Tp _M_data
Definition bslstp_slist.h:142
Definition bslmf_isfundamental.h:330