BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslalg_dequeiterator.h
Go to the documentation of this file.
1/// @file bslalg_dequeiterator.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslalg_dequeiterator.h -*-C++-*-
8#ifndef INCLUDED_BSLALG_DEQUEITERATOR
9#define INCLUDED_BSLALG_DEQUEITERATOR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslalg_dequeiterator bslalg_dequeiterator
15/// @brief Provide a primitive iterator over deque data structures.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslalg
19/// @{
20/// @addtogroup bslalg_dequeiterator
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslalg_dequeiterator-purpose"> Purpose</a>
25/// * <a href="#bslalg_dequeiterator-classes"> Classes </a>
26/// * <a href="#bslalg_dequeiterator-description"> Description </a>
27/// * <a href="#bslalg_dequeiterator-usage"> Usage </a>
28///
29/// # Purpose {#bslalg_dequeiterator-purpose}
30/// Provide a primitive iterator over deque data structures.
31///
32/// # Classes {#bslalg_dequeiterator-classes}
33///
34/// - bslalg::DequeIterator: primitive iterator over a deque data structure
35///
36/// @see bslalg_dequeimputil, bslalg_dequeprimitives
37///
38/// # Description {#bslalg_dequeiterator-description}
39/// This component provides an in-core value semantic class,
40/// `bslalg::DequeIterator`, that is a primitive iterator type for enumerating
41/// elements in a deque (implemented in the form of a dynamic array) knowing
42/// only its value type and a nominal block size. Conceptually, a deque is an
43/// array of block pointers, each block capable of containing a fixed number of
44/// objects. An element in the deque is identified by an iterator that consists
45/// of two pointers:
46/// * a pointer to the block pointer array, and
47/// * a pointer to a value within the block referred to by the first pointer.
48///
49/// Dereferencing the iterator dereferences the second pointer. Incrementing or
50/// decrementing the iterator consists of incrementing the value pointer, unless
51/// the iterator crosses a block boundary in which case it must increment or
52/// decrement its pointer to the block pointer. Computing the distance between
53/// two iterators involves figuring out how many block are in between and how
54/// the offsets-in-block differ.
55///
56/// Note that an iterator is valid as long as the element it points to still
57/// belongs to the deque *and* there is no reallocation of the block pointer
58/// array. Inserting elements at either end of the deque usually maintains
59/// iterator validity, but inserting enough elements at the end of the queue
60/// might force the creating of sufficiently many blocks to trigger a
61/// reallocation of the block pointer array and invalidate all iterators into
62/// the deque; how many depends on the distances between the front and back of
63/// the deque and the first/last iterator in the block pointer array (19 in the
64/// picture below).
65///
66/// The picture is as follows:
67/// @code
68/// v--- Iterator to 'I': ptr to this BlockPtr
69/// +-----+-----+-----+-----+-----+-----+-----+-----+
70/// | * | * | * | * | * | * | * | * | BlockPtr array
71/// +-----+-----+--|--+--|--+--|--+--|--+-----+-----+
72/// | | | | Block
73/// | | | | +---+---+---+---+---+---+---+---+
74/// | | | `--| V | W | X | Y | Z | | | |
75/// | | | +---+---+---+---+---+---+---+---+
76/// | | | Block
77/// | | | +---+---+---+---+---+---+---+---+
78/// | | `--| N | O | P | Q | R | S | T | U |
79/// | | +---+---+---+---+---+---+---+---+
80/// | | v---- Iterator to 'I': ptr to value
81/// | | +---+---+---+---+---+---+---+---+
82/// | `--| F | G | H | I | J | K | L | M |
83/// | +---+---+---+---+---+---+---+---+
84/// | Block
85/// | +---+---+---+---+---+---+---+---+
86/// `--| | | | A | B | C | D | E |
87/// +---+---+---+---+---+---+---+---+
88/// @endcode
89/// Depicted above is a deque consisting of eight block pointers, only four
90/// actually used to point to blocks of eight elements. In the first block, the
91/// first three elements are uninitialized, and the twenty six elements follow
92/// in sequence across the different blocks. An iterator to the `I` element
93/// consists of a pointer to the fourth block pointer and a pointer to the sixth
94/// element of that block. The value of the corresponding deque would be
95/// `[ A, B, C, ... X, Y, Z ]`, its logical length 26, and its capacity would be
96/// 19 (the minimum number of prepend/append to force a reallocation of the
97/// block pointer array).
98///
99/// This component does not provide the full interface of a C++ standard library
100/// iterator as we do not want a dependency on `iterator_traits` in a package
101/// below `bslstl`. `bslalg::DequeIterator` provides the minimal necessary set
102/// of features to implement such an iterator for a standard conforming `deque`
103/// implementation in a higher level component.
104///
105/// ## Usage {#bslalg_dequeiterator-usage}
106///
107///
108/// This component is for use by the `bslstl` package. Other clients should use
109/// the STL deque (in header `<deque>`).
110/// @}
111/** @} */
112/** @} */
113
114/** @addtogroup bsl
115 * @{
116 */
117/** @addtogroup bslalg
118 * @{
119 */
120/** @addtogroup bslalg_dequeiterator
121 * @{
122 */
123
124#include <bslscm_version.h>
125
126#include <bslalg_dequeimputil.h>
127
129
130#include <bsls_assert.h>
132
133#include <cstddef> // std::size_t, std::ptrdiff_t
134
135
136
137namespace bslalg {
138
139template <class VALUE_TYPE, int BLOCK_LENGTH>
140class DequeIterator;
141
142template <class VALUE_TYPE>
143class DequeIterator<VALUE_TYPE, 1>;
144
145 // ===================
146 // class DequeIterator
147 // ===================
148
149/// Implementation of a deque iterator, parameterized by the `VALUE_TYPE`,
150/// for a deque with the parameterized `BLOCK_LENGTH`, and suitable for use by the `bslstl::RandomAccessIterator` adapter.
151///
152/// \note Note that `BLOCK_LENGTH`
153/// is the number of items of `VALUE_TYPE` within a block, not the size of a
154/// block in bytes.
155///
156/// See @ref bslalg_dequeiterator
157template <class VALUE_TYPE, int BLOCK_LENGTH>
159
160 // PRIVATE TYPES
162 typedef typename DequeImpUtil::BlockPtr BlockPtr;
163 typedef DequeIterator<VALUE_TYPE, BLOCK_LENGTH> IteratorType;
164
165 // DATA
166 BlockPtr *d_blockPtr_p;
167 VALUE_TYPE *d_value_p;
168
169 // FRIENDS
170
171 /// Return `true` if the specified `lhs` iterator points to the same
172 /// element in the same block as the specified `rhs` iterator, and `false` otherwise.
173 ///
174 /// \pre The behavior is undefined unless `lhs` and `rhs` are iterators over the same deque.
175 ///
176 /// \note Note that this friend is a
177 /// regular functon, not a function template, so there is no way to
178 /// declare it outside the class in order to provide the definition.
179 friend bool operator==(const DequeIterator& lhs, const DequeIterator& rhs)
180 {
181 return lhs.d_value_p == rhs.d_value_p;
182 }
183
184#ifdef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
185 /// Perform a three-way comparison between the specified `lhs` and `rhs` iterators.
186 ///
187 /// \pre The behavior is undefined unless `lhs` and `rhs` are
188 /// iterators over the same deque.
189 friend auto operator<=>(const DequeIterator& lhs, const DequeIterator& rhs)
190 {
191 auto result = lhs.d_blockPtr_p <=> rhs.d_blockPtr_p;
192 return result == 0 ? lhs.d_value_p <=> rhs.d_value_p
193 : result;
194 }
195#else
196 /// Return `true` if the specified `lhs` iterator points to a different
197 /// element in the same block as the specified `rhs` iterator, or points
198 /// to an element in a different block to the `rhs` iterator, and `false` otherwise.
199 ///
200 /// \pre The behavior is undefined unless `lhs` and `rhs` are iterators over the same deque.
201 ///
202 /// \note Note that this friend is a
203 /// regular functon, not a function template, so there is no way to
204 /// declare it outside the class in order to provide the definition.
205 friend bool operator!=(const DequeIterator& lhs, const DequeIterator& rhs)
206 {
207 return lhs.d_value_p != rhs.d_value_p;
208 }
209
210 /// Return `true` if the specified `lhs` iterator points to an element
211 /// in a previous block or in a previous position in the same block as
212 /// the specified `rhs` iterator, and `false` otherwise.
213 ///
214 /// \pre The behavior is undefined unless `lhs` and `rhs` are iterators over the same deque.
215 ///
216 /// \note Note that this friend is a regular functon, not a function
217 /// template, so there is no way to declare it outside the class in
218 /// order to provide the definition.
219 friend bool operator<(const DequeIterator& lhs, const DequeIterator& rhs)
220 {
221 if (lhs.d_blockPtr_p == rhs.d_blockPtr_p) {
222 return lhs.d_value_p < rhs.d_value_p; // RETURN
223 }
224 else {
225 return lhs.d_blockPtr_p < rhs.d_blockPtr_p; // RETURN
226 }
227 }
228#endif
229
230 public:
231 // CREATORS
232
233 /// Create a singular iterator (i.e., having internal null pointers).
235
236 /// Create an iterator pointing to the first element in the block
237 /// pointed to by the specified `blockPtrPtr`.
238 explicit
239 DequeIterator(BlockPtr *blockPtrPtr);
240
241 /// Create an iterator pointing to the element at the specified
242 /// `valuePtr` address in the block pointed to by the specified `blockPtrPtr`.
243 ///
244 /// \pre The behavior is undefined unless `valuePtr` points
245 /// into the block `*blockPtrPtr`.
246 DequeIterator(BlockPtr *blockPtrPtr, VALUE_TYPE *valuePtr);
247
248 // MANIPULATORS
249
250 /// Increment this iterator to point to the next element in the
251 /// corresponding deque (i.e., the element following the current one in
252 /// the same block or, if the current element is the last one in the
253 /// block, the first element in the next block).
254 void operator++();
255
256 /// Decrement this iterator to point to the previous element in the
257 /// corresponding deque (i.e., the element preceding the current one in
258 /// the same block or, if the current element is the first one in the
259 /// block, the last element in the previous block).
260 void operator--();
261
262 /// Advance this iterator by the specified `offset`.
263 void operator+=(std::ptrdiff_t offset);
264
265 /// Move this iterator backward by the specified `offset`.
266 void operator-=(std::ptrdiff_t offset);
267
268 /// Set this iterator to point to the first element of the next block.
269 void nextBlock();
270
271 /// Set this iterator to point to the first (not the last) element of
272 /// the previous block.
273 void previousBlock();
274
275 /// Set this iterator to point to the first element of the block pointed
276 /// to by the specified `blockPtrPtr`.
277 void setBlock(BlockPtr *blockPtrPtr);
278
279 /// Decrement this iterator to point to the next element in the block of the corresponding deque.
280 ///
281 /// \pre The behavior is undefined unless this
282 /// iterator is pointed to a valid position of the deque.
283 ///
284 /// \note Note that this method is used only for optimization purposes in
285 /// `bslstl_Deque`, and clients of this package should not use this
286 /// directly.
287 void valuePtrDecrement();
288
289 /// Increment this iterator to point to the next element in the block of the corresponding deque.
290 ///
291 /// \pre The behavior is undefined unless this
292 /// iterator is pointed to a valid position of the deque.
293 ///
294 /// \note Note that this method is used only for optimization purposes in
295 /// `bslstl_Deque`, and clients of this package should not use this
296 /// directly.
297 void valuePtrIncrement();
298
299 // ACCESSORS
300
301 /// Return a reference to the parameterized `VALUE_TYPE` object pointed to by this iterator.
302 ///
303 /// \note Note that this value is modifiable if
304 /// `VALUE_TYPE` is modifiable, and non-modifiable if it is not.
305 VALUE_TYPE& operator*() const;
306
307 /// Return an iterator pointing the element at the specified `offset`
308 /// after this iterator.
309 DequeIterator operator+(std::ptrdiff_t offset) const;
310
311 /// Return an iterator pointing the element at the specified `offset`
312 /// before this iterator.
313 DequeIterator operator-(std::ptrdiff_t offset) const;
314
315 /// Return the distance between this iterator and the specified `rhs`
316 /// iterator.
317 std::ptrdiff_t operator-(const DequeIterator& rhs) const;
318
319 /// Return the address of the first element in the block pointed to by
320 /// this iterator.
321 VALUE_TYPE *blockBegin() const;
322
323 /// Return the address of (one-past) the last element in the block
324 /// pointed to by this iterator.
325 VALUE_TYPE *blockEnd() const;
326
327 /// Return the address of the block pointer pointed to by this iterator.
328 BlockPtr *blockPtr() const;
329
330 /// Return the offset of the element pointed to by this iterator, from
331 /// the beginning of the block containing it.
332 std::size_t offsetInBlock() const;
333
334 /// Return the number of elements in the block pointed to by this
335 /// iterator, until the end of this block, starting at (and including)
336 /// the element pointed to by this iterator.
337 std::size_t remainingInBlock() const;
338
339 /// Return the address of the parameterized `VALUE_TYPE` object pointed
340 /// to by this iterator.
341 VALUE_TYPE *valuePtr() const;
342};
343
344// PARTIAL SPECIALIZATION
345
346/// This partial specialization of `DequeIterator` for the case when there
347/// is a single element per block uses simpler storage and a simpler
348/// implementation. The contract for all functions is the same, and so not
349/// repeated.
350template <class VALUE_TYPE>
351class DequeIterator<VALUE_TYPE, 1> {
352
353 // PRIVATE TYPES
355 typedef typename DequeImpUtil::BlockPtr BlockPtr;
357
358 // DATA
359 BlockPtr *d_blockPtr_p; // pointer to BlockPtr within BlockPtr array
360 VALUE_TYPE *d_value_p; // pointer to element referenced by iterator
361
362 // FRIENDS
363 friend bool operator==(const DequeIterator& lhs, const DequeIterator& rhs)
364 {
365 return lhs.d_blockPtr_p == rhs.d_blockPtr_p;
366 }
367
368#ifdef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
369 friend auto operator<=>(const DequeIterator& lhs, const DequeIterator& rhs)
370 {
371 return lhs.d_blockPtr_p <=> rhs.d_blockPtr_p;
372 }
373#else
374 friend bool operator!=(const DequeIterator& lhs, const DequeIterator& rhs)
375 {
376 return lhs.d_blockPtr_p != rhs.d_blockPtr_p;
377 }
378
379 friend bool operator<(const DequeIterator& lhs, const DequeIterator& rhs)
380 {
381 return lhs.d_blockPtr_p < rhs.d_blockPtr_p;
382 }
383#endif
384
385 public:
386 // CREATORS
388 DequeIterator(BlockPtr *blockPtrPtr);
389 DequeIterator(BlockPtr *blockPtrPtr, VALUE_TYPE *valuePtr);
390
391 // MANIPULATORS
392 void operator++();
393 void operator--();
394 void operator+=(std::ptrdiff_t offset);
395 void operator-=(std::ptrdiff_t offset);
396
397 void nextBlock();
398 void previousBlock();
399 void setBlock(BlockPtr *blockPtrPtr);
400 void valuePtrDecrement();
401 void valuePtrIncrement();
402
403 // ACCESSORS
404 VALUE_TYPE& operator*() const;
405 DequeIterator operator+(std::ptrdiff_t offset) const;
406 DequeIterator operator-(std::ptrdiff_t offset) const;
407 std::ptrdiff_t operator-(const DequeIterator& rhs) const;
408 VALUE_TYPE *blockBegin() const;
409 VALUE_TYPE *blockEnd() const;
410 BlockPtr *blockPtr() const;
411 std::size_t offsetInBlock() const;
412 std::size_t remainingInBlock() const;
413 VALUE_TYPE *valuePtr() const;
414};
415
416// ============================================================================
417// INLINE FUNCTION DEFINITIONS
418// ============================================================================
419
420 // -------------------
421 // class DequeIterator
422 // -------------------
423
424// CREATORS
425template <class VALUE_TYPE, int BLOCK_LENGTH>
426inline
428: d_blockPtr_p(0)
429, d_value_p(0)
430{
431}
432
433template <class VALUE_TYPE, int BLOCK_LENGTH>
434inline
436: d_blockPtr_p(blockPtrPtr)
437, d_value_p(reinterpret_cast<VALUE_TYPE*>(*blockPtrPtr))
438{
439}
440
441template <class VALUE_TYPE, int BLOCK_LENGTH>
442inline
444 VALUE_TYPE *valuePtr)
445: d_blockPtr_p(blockPtrPtr)
446, d_value_p(valuePtr)
447{
448 // Trivially true, or undefined behavior, without the cast.
450 reinterpret_cast<bsls::Types::UintPtr>((void*)blockPtrPtr[0]->d_data)
451 <= reinterpret_cast<bsls::Types::UintPtr>((void*)valuePtr));
452 BSLS_ASSERT_SAFE(valuePtr - blockPtrPtr[0]->d_data < BLOCK_LENGTH);
453}
454
455// MANIPULATORS
456template <class VALUE_TYPE, int BLOCK_LENGTH>
458{
459 if (1 == this->remainingInBlock()) {
460 ++d_blockPtr_p;
461 d_value_p = this->blockBegin();
462 }
463 else {
464 ++d_value_p;
465 }
466}
467
468template <class VALUE_TYPE, int BLOCK_LENGTH>
470{
471 if (0 == this->offsetInBlock()) {
472 --d_blockPtr_p;
473 d_value_p = this->blockEnd();
474 }
475 --d_value_p;
476}
477
478template <class VALUE_TYPE, int BLOCK_LENGTH>
479void
481{
482 offset += offsetInBlock();
483 if (offset >= 0) {
484 d_blockPtr_p += offset / BLOCK_LENGTH;
485 d_value_p = blockBegin() + (offset % BLOCK_LENGTH);
486 }
487 else {
488 d_blockPtr_p -= (-offset - 1) / BLOCK_LENGTH + 1;
489 d_value_p = blockEnd() - ((-offset - 1) % BLOCK_LENGTH + 1);
490 }
491}
492
493template <class VALUE_TYPE, int BLOCK_LENGTH>
494inline
495void
497{
498 this->operator+=(-offset);
499}
500
501template <class VALUE_TYPE, int BLOCK_LENGTH>
502inline
504{
505 ++d_blockPtr_p;
506 d_value_p = this->blockBegin();
507}
508
509template <class VALUE_TYPE, int BLOCK_LENGTH>
510inline
512{
513 --d_blockPtr_p;
514 d_value_p = this->blockBegin();
515}
516
517template <class VALUE_TYPE, int BLOCK_LENGTH>
518inline
520{
521 d_blockPtr_p = blockPtrPtr;
522 d_value_p = this->blockBegin();
523}
524
525template <class VALUE_TYPE, int BLOCK_LENGTH>
526inline
528{
529 BSLS_ASSERT_SAFE(d_blockPtr_p[0]->d_data <= d_value_p);
530 BSLS_ASSERT_SAFE(d_value_p < d_blockPtr_p[0]->d_data + BLOCK_LENGTH);
531
532 --d_value_p;
533}
534
535template <class VALUE_TYPE, int BLOCK_LENGTH>
536inline
538{
539 BSLS_ASSERT_SAFE(d_blockPtr_p[0]->d_data <= d_value_p);
540 BSLS_ASSERT_SAFE(d_value_p < d_blockPtr_p[0]->d_data + BLOCK_LENGTH);
541
542 ++d_value_p;
543}
544
545// ACCESSORS
546template <class VALUE_TYPE, int BLOCK_LENGTH>
547inline
548VALUE_TYPE&
550{
551 return *d_value_p;
552}
553
554template <class VALUE_TYPE, int BLOCK_LENGTH>
555inline
558{
559 DequeIterator ret(*this);
560 ret += offset;
561 return ret;
562}
563
564template <class VALUE_TYPE, int BLOCK_LENGTH>
565inline
568{
569 DequeIterator ret(*this);
570 ret += -offset;
571 return ret;
572}
573
574template <class VALUE_TYPE, int BLOCK_LENGTH>
575std::ptrdiff_t
578{
579 if (d_blockPtr_p == rhs.d_blockPtr_p) {
580 return d_value_p - rhs.d_value_p; // RETURN
581 }
582 else {
583 const int numFullBlocks = static_cast<int>(
584 this->d_blockPtr_p - rhs.d_blockPtr_p - 1);
585 return (numFullBlocks * BLOCK_LENGTH +
586 rhs.remainingInBlock() + this->offsetInBlock()); // RETURN
587 }
588}
589
590template <class VALUE_TYPE, int BLOCK_LENGTH>
591inline
592VALUE_TYPE *
594{
595 return reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p);
596}
597
598template <class VALUE_TYPE, int BLOCK_LENGTH>
599inline
600VALUE_TYPE *
602{
603 return reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p) + BLOCK_LENGTH;
604}
605
606template <class VALUE_TYPE, int BLOCK_LENGTH>
607inline
608typename
611{
612 return d_blockPtr_p;
613}
614
615template <class VALUE_TYPE, int BLOCK_LENGTH>
616inline
617std::size_t
619{
620 return d_value_p - blockBegin();
621}
622
623template <class VALUE_TYPE, int BLOCK_LENGTH>
624inline
625std::size_t
627{
628 return blockBegin() + BLOCK_LENGTH - d_value_p;
629}
630
631template <class VALUE_TYPE, int BLOCK_LENGTH>
632inline
633VALUE_TYPE *
635{
636 return d_value_p;
637}
638
639 // ---------------------------------
640 // class DequeIterator<VALUE_TYPE,1>
641 // ---------------------------------
642
643// CREATORS
644template <class VALUE_TYPE>
645inline
647: d_blockPtr_p(0)
648, d_value_p(0)
649{
650}
651
652template <class VALUE_TYPE>
653inline
655: d_blockPtr_p(blockPtrPtr)
656, d_value_p(reinterpret_cast<VALUE_TYPE*>(*blockPtrPtr))
657{
658}
659
660template <class VALUE_TYPE>
661inline
663 VALUE_TYPE *valuePtr)
664: d_blockPtr_p(blockPtrPtr)
665, d_value_p(valuePtr)
666{
667 BSLS_ASSERT_SAFE((*blockPtrPtr)->d_data == valuePtr);
668}
669
670// MANIPULATORS
671template <class VALUE_TYPE>
672inline
674{
675 ++d_blockPtr_p;
676 d_value_p = reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p);
677}
678
679template <class VALUE_TYPE>
680inline
682{
683 --d_blockPtr_p;
684 d_value_p = reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p);
685}
686
687template <class VALUE_TYPE>
688inline
690{
691 d_blockPtr_p += offset;
692 d_value_p = reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p);
693}
694
695template <class VALUE_TYPE>
696inline
698{
699 this->operator+=(-offset);
700}
701
702template <class VALUE_TYPE>
703inline
705{
706 ++d_blockPtr_p;
707 d_value_p = reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p);
708}
709
710template <class VALUE_TYPE>
711inline
713{
714 --d_blockPtr_p;
715 d_value_p = reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p);
716}
717
718template <class VALUE_TYPE>
719inline
721{
722 d_blockPtr_p = blockPtrPtr;
723 d_value_p = reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p);
724}
725
726template <class VALUE_TYPE>
727inline
729{
730 // This should never be called for 'BLOCK_LENGTH' of 1
732}
733
734template <class VALUE_TYPE>
735inline
737{
738 // This should never be called for 'BLOCK_LENGTH' of 1
740}
741
742// ACCESSORS
743template <class VALUE_TYPE>
744inline
746{
747 return *d_value_p;
748}
749
750template <class VALUE_TYPE>
751inline
753DequeIterator<VALUE_TYPE, 1>::operator+(std::ptrdiff_t offset) const
754{
755 return DequeIterator<VALUE_TYPE, 1>(d_blockPtr_p + offset);
756}
757
758template <class VALUE_TYPE>
759inline
761DequeIterator<VALUE_TYPE, 1>::operator-(std::ptrdiff_t offset) const
762{
763 return DequeIterator<VALUE_TYPE, 1>(d_blockPtr_p - offset);
764}
765
766template <class VALUE_TYPE>
767inline
768std::ptrdiff_t
770 const DequeIterator<VALUE_TYPE, 1>& rhs) const
771{
772 return d_blockPtr_p - rhs.d_blockPtr_p;
773}
774
775template <class VALUE_TYPE>
776inline
777VALUE_TYPE *
779{
780 return reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p);
781}
782
783template <class VALUE_TYPE>
784inline
785VALUE_TYPE *
787{
788 return reinterpret_cast<VALUE_TYPE*>(*d_blockPtr_p) + 1;
789}
790
791template <class VALUE_TYPE>
792inline
793typename
796{
797 return d_blockPtr_p;
798}
799
800template <class VALUE_TYPE>
801inline
802std::size_t
804{
805 return 0;
806}
807
808template <class VALUE_TYPE>
809inline
810std::size_t
815
816template <class VALUE_TYPE>
817inline
818VALUE_TYPE *
820{
821 return d_value_p;
822}
823
824} // close package namespace
825
826#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
827// ============================================================================
828// BACKWARD COMPATIBILITY
829// ============================================================================
830
831#ifdef bslalg_DequeIterator
832#undef bslalg_DequeIterator
833#endif
834/// This alias is defined for backward compatibility.
835#define bslalg_DequeIterator bslalg::DequeIterator
836#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
837
838
839
840// ============================================================================
841// TYPE TRAITS
842// ============================================================================
843
844
845namespace bslmf {
846
847template <class VALUE_TYPE, int BLOCK_LENGTH>
848struct IsBitwiseCopyable<BloombergLP::bslalg::DequeIterator<VALUE_TYPE,
849 BLOCK_LENGTH> >
851{};
852
853} // close namespace bslmf
854
855
856#endif
857
858// ----------------------------------------------------------------------------
859// Copyright 2013 Bloomberg Finance L.P.
860//
861// Licensed under the Apache License, Version 2.0 (the "License");
862// you may not use this file except in compliance with the License.
863// You may obtain a copy of the License at
864//
865// http://www.apache.org/licenses/LICENSE-2.0
866//
867// Unless required by applicable law or agreed to in writing, software
868// distributed under the License is distributed on an "AS IS" BASIS,
869// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
870// See the License for the specific language governing permissions and
871// limitations under the License.
872// ----------------------------- END-OF-FILE ----------------------------------
873
874/** @} */
875/** @} */
876/** @} */
Definition bslalg_dequeiterator.h:351
std::ptrdiff_t operator-(const DequeIterator &rhs) const
friend bool operator<(const DequeIterator &lhs, const DequeIterator &rhs)
Definition bslalg_dequeiterator.h:379
friend bool operator!=(const DequeIterator &lhs, const DequeIterator &rhs)
Definition bslalg_dequeiterator.h:374
friend bool operator==(const DequeIterator &lhs, const DequeIterator &rhs)
Definition bslalg_dequeiterator.h:363
Definition bslalg_dequeiterator.h:158
void previousBlock()
Definition bslalg_dequeiterator.h:511
std::size_t offsetInBlock() const
Definition bslalg_dequeiterator.h:618
std::size_t remainingInBlock() const
Definition bslalg_dequeiterator.h:626
void setBlock(BlockPtr *blockPtrPtr)
Definition bslalg_dequeiterator.h:519
void valuePtrDecrement()
Definition bslalg_dequeiterator.h:527
VALUE_TYPE * valuePtr() const
Definition bslalg_dequeiterator.h:634
void nextBlock()
Set this iterator to point to the first element of the next block.
Definition bslalg_dequeiterator.h:503
void valuePtrIncrement()
Definition bslalg_dequeiterator.h:537
void operator-=(std::ptrdiff_t offset)
Move this iterator backward by the specified offset.
Definition bslalg_dequeiterator.h:496
void operator+=(std::ptrdiff_t offset)
Advance this iterator by the specified offset.
Definition bslalg_dequeiterator.h:480
friend bool operator<(const DequeIterator &lhs, const DequeIterator &rhs)
Definition bslalg_dequeiterator.h:219
void operator--()
Definition bslalg_dequeiterator.h:469
DequeIterator operator-(std::ptrdiff_t offset) const
Definition bslalg_dequeiterator.h:567
friend bool operator!=(const DequeIterator &lhs, const DequeIterator &rhs)
Definition bslalg_dequeiterator.h:205
void operator++()
Definition bslalg_dequeiterator.h:457
BlockPtr * blockPtr() const
Return the address of the block pointer pointed to by this iterator.
Definition bslalg_dequeiterator.h:610
friend bool operator==(const DequeIterator &lhs, const DequeIterator &rhs)
Definition bslalg_dequeiterator.h:179
VALUE_TYPE * blockBegin() const
Definition bslalg_dequeiterator.h:593
VALUE_TYPE & operator*() const
Definition bslalg_dequeiterator.h:549
DequeIterator()
Create a singular iterator (i.e., having internal null pointers).
Definition bslalg_dequeiterator.h:427
VALUE_TYPE * blockEnd() const
Definition bslalg_dequeiterator.h:601
DequeIterator operator+(std::ptrdiff_t offset) const
Definition bslalg_dequeiterator.h:557
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlc_flathashmap.h:2218
Definition bdlbb_blob.h:579
Definition bslalg_dequeimputil.h:147
Definition bslalg_dequeimputil.h:126
Definition bslmf_isbitwisecopyable.h:298
std::size_t UintPtr
Definition bsls_types.h:128