General Utility Library for C++17 26.5.0
SlidingBuffer.h
Go to the documentation of this file.
1
26#ifndef GUL17_SLIDINGBUFFER_H_
27#define GUL17_SLIDINGBUFFER_H_
28
29#include <algorithm>
30#include <array>
31#include <ostream>
32#include <vector>
33
34#include "gul17/cat.h"
35#include "gul17/internal.h"
36
37namespace gul17 {
38
69enum class ShrinkBehavior { keep_front_elements, keep_back_elements };
70
179template<typename ElementT, std::size_t fixed_capacity = 0u,
180 typename Container = typename std::conditional_t<(fixed_capacity >= 1u),
181 std::array<ElementT, fixed_capacity>,
182 std::vector<ElementT>>
183 >
185public:
186 template <typename>
193 using size_type = typename Container::size_type;
195 using difference_type = typename Container::difference_type;
197 using reference = typename Container::reference;
199 using const_reference = typename Container::const_reference;
201 using pointer = typename Container::pointer;
203 using const_pointer = typename Container::const_pointer;
209 using reverse_iterator = std::reverse_iterator<iterator>;
211 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
212
225 SlidingBuffer() = default;
227 SlidingBuffer(SlidingBuffer const&) = default;
236
248
249protected:
250
253 size_type idx_begin_{ 0u };
256 size_type idx_end_{ 0u };
258 bool full_{ false };
260 Container storage_{ };
261
262public:
273 auto pop_back() -> void
274 {
275 decrease_idx(idx_end_);
276 full_ = false;
277 }
278
290 auto pop_front() -> void
291 {
292 increase_idx(idx_begin_);
293 full_ = false;
294 }
295
309 auto push_back(const value_type& in) -> void
310 {
311 storage_[idx_end_] = in;
312
313 increase_idx(idx_end_);
314 if (full_)
315 increase_idx(idx_begin_);
316 else if (idx_end_ == idx_begin_)
317 full_ = true;
318 }
319
323 auto push_back(value_type&& in) -> void
324 {
325 storage_[idx_end_] = std::move(in);
326
327 increase_idx(idx_end_);
328 if (full_)
329 increase_idx(idx_begin_);
330 else if (idx_end_ == idx_begin_)
331 full_ = true;
332 }
333
347 auto push_front(const value_type& in) -> void
348 {
349 decrease_idx(idx_begin_);
350
351 if (full_)
352 decrease_idx(idx_end_);
353 else if (idx_end_ == idx_begin_)
354 full_ = true;
355
356 storage_[idx_begin_] = in;
357 }
358
362 auto push_front(value_type&& in) -> void
363 {
364 decrease_idx(idx_begin_);
365
366 if (full_)
367 decrease_idx(idx_end_);
368 else if (idx_end_ == idx_begin_)
369 full_ = true;
370
371 storage_[idx_begin_] = std::move(in);
372 }
373
385 {
386 idx += idx_begin_;
387
388 return (idx >= capacity()) ? storage_[idx - capacity()] : storage_[idx];
389 }
390
394 auto operator[](size_type idx) const noexcept -> const_reference
395 {
396 idx += idx_begin_;
397
398 return (idx >= capacity()) ? storage_[idx - capacity()] : storage_[idx];
399 }
400
412 auto at(const size_type idx) noexcept(false) -> reference
413 {
414 auto const s = size();
415 if (idx >= s) {
416 throw std::out_of_range(gul17::cat("SlidingBuffer::", __func__,
417 ": idx (which is ", idx, ") >= this->size() (which is ", s, ")"));
418 }
419 return operator[](idx);
420 }
421
425 auto at(const size_type idx) const noexcept(false) -> const_reference
426 {
427 auto const s = size();
428 if (idx >= s) {
429 throw std::out_of_range(gul17::cat("SlidingBuffer::", __func__,
430 ": idx (which is ", idx, ") >= this->size() (which is ", s, ")"));
431 }
432 return operator[](idx);
433 }
434
442 {
443 return storage_[idx_begin_];
444 }
445
450 {
451 return storage_[idx_begin_];
452 }
453
461 {
462 if (idx_end_ == 0)
463 return storage_[capacity() - 1];
464 else
465 return storage_[idx_end_ - 1];
466 }
467
472 {
473 if (idx_end_ == 0)
474 return storage_[capacity() - 1];
475 else
476 return storage_[idx_end_ - 1];
477 }
478
487 {
488 if (full_)
489 return capacity();
490
491 if (idx_end_ >= idx_begin_)
492 return idx_end_ - idx_begin_;
493 else
494 return idx_end_ + capacity() - idx_begin_;
495 }
496
504 auto constexpr capacity() const noexcept -> size_type
505 {
506 return (fixed_capacity > 0) ? fixed_capacity : storage_.size();
507 }
508
517 auto filled() const noexcept -> bool
518 {
519 return full_;
520 }
521
529 auto clear() -> void
530 {
531 full_ = false;
532 idx_begin_ = 0u;
533 idx_end_ = 0u;
534
535 // Fill with new empty elements to possibly trigger RAII in the elements
536 std::fill(storage_.begin(), storage_.end(), value_type{});
537 }
538
558 auto resize(size_type new_capacity, ShrinkBehavior shrink_behavior = ShrinkBehavior::keep_front_elements) -> void
559 {
560 static_assert(fixed_capacity == 0u,
561 "resize() only possible if the underlying container is resizable");
562 change_capacity(new_capacity, shrink_behavior);
563 }
564
569 auto reserve(size_type size, ShrinkBehavior shrink_behavior = ShrinkBehavior::keep_front_elements) -> void
570 {
571 static_assert(fixed_capacity == 0u,
572 "reserve() only possible if the underlying container is resizable");
573 change_capacity(size, shrink_behavior);
574 }
575
581 auto empty() const noexcept -> bool
582 {
583 return (not full_) and (idx_begin_ == idx_end_);
584 }
585
593 auto friend operator<< (std::ostream& s,
595 {
596 auto const size = buffer.size();
597 // We can not use range-for here, because of SlidingBufferExposed<>'s un-wrapped iterators
598 for (auto i = size_type{ 0 }; i < size; ++i)
599 s << buffer[i] << " ";
600 return s << '\n';
601 }
602
643 template <typename BufferPointer>
645 {
646 protected:
648 size_type position_{ 0 };
649 private:
651 BufferPointer buffer_;
652
653 public:
654 // Set of 5 member types that are needed by std::iterator_traits:
655
657 using iterator_category = std::random_access_iterator_tag;
659 using value_type = ElementT;
661 using difference_type = std::ptrdiff_t;
666
673 explicit SlidingBufferIterator(BufferPointer buff, size_type num = 0) noexcept
674 : position_{ num }
675 , buffer_{ buff }
676 {
677 }
678
681 {
682 ++position_;
683 return *this;
684 }
685
687 auto operator++(int) noexcept -> SlidingBufferIterator
688 {
689 auto previous = *this;
690 ++(*this);
691 return previous;
692 }
693
696 {
697 position_ += static_cast<size_type>(d);
698 return *this;
699 }
700
702 friend auto
705 {
706 return SlidingBufferIterator{ it.buffer_, it.position_ + static_cast<size_type>(d) };
707 }
708
710 friend auto
713 {
714 return SlidingBufferIterator{ it.buffer_, it.position_ + static_cast<size_type>(d) };
715 }
716
719 {
720 --position_;
721 return *this;
722 }
723
725 auto operator--(int) noexcept -> SlidingBufferIterator
726 {
727 auto previous = *this;
728 --(*this);
729 return previous;
730 }
731
734 {
735 position_ -= static_cast<size_type>(d);
736 return *this;
737 }
738
740 friend auto
743 {
744 return SlidingBufferIterator{ it.buffer_, it.position_ - static_cast<size_type>(d) };
745 }
746
748 friend auto
751 {
752 return static_cast<difference_type>(lhs.position_ - rhs.position_);
753 }
754
756 auto operator*() const noexcept -> typename std::conditional_t<
757 std::is_const<std::remove_pointer_t<BufferPointer>>::value,
759 {
760 return (*buffer_)[position_];
761 }
762
764 auto operator->() const noexcept -> typename std::conditional_t<
765 std::is_const<std::remove_pointer_t<BufferPointer>>::value,
767 {
768 return &(*buffer_)[position_];
769 }
770
772 auto operator[](difference_type offs) noexcept -> typename std::conditional_t<
773 std::is_const<std::remove_pointer_t<BufferPointer>>::value,
775 {
776 return *(*this + offs);
777 }
778
784 friend auto
786 -> bool
787 {
788 return lhs.position_ == rhs.position_;
789 }
790
796 friend auto
798 -> bool
799 {
800 return not(lhs == rhs);
801 }
802
806 friend auto
808 -> bool
809 {
810 return lhs.position_ > rhs.position_;
811 }
812
814 friend auto
815 operator<(const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept
816 -> bool
817 {
818 return lhs.position_ < rhs.position_;
819 }
820
825 friend auto
827 -> bool
828 {
829 return lhs.position_ >= rhs.position_;
830 }
831
836 friend auto
837 operator<=(const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept
838 -> bool
839 {
840 return lhs.position_ <= rhs.position_;
841 }
842 };
843
850 {
851 return iterator{ this, 0 };
852 }
853
856 {
857 return const_iterator{ this, 0 };
858 }
859
866 {
867 return std::make_reverse_iterator(end());
868 }
869
877 {
878 return iterator{ this, size() };
879 }
880
883 {
884 return const_iterator{ this, size() };
885 }
886
895 {
896 return std::make_reverse_iterator(begin());
897 }
898
905 {
906 return const_iterator{ this, 0 };
907 }
908
915 {
916 return std::make_reverse_iterator(cend());
917 }
918
927 {
928 return const_iterator{ this, size() };
929 }
930
939 {
940 return std::make_reverse_iterator(cbegin());
941 }
942
943private:
944 void decrease_idx(size_t &idx) noexcept
945 {
946 if (idx == 0)
947 idx = capacity() - 1;
948 else
949 --idx;
950 }
951
952 void increase_idx(size_t &idx) noexcept
953 {
954 ++idx;
955
956 if (idx >= capacity())
957 idx = 0;
958 }
959
960protected:
975 auto change_capacity(size_type new_capacity, ShrinkBehavior shrink_behavior = ShrinkBehavior::keep_front_elements) -> void
976 {
977 auto const old_capacity = capacity();
978 auto const old_size = size();
979
981 // No change
983 return;
984
986 // Vanishing
987 if (new_capacity == 0) {
988 storage_.resize(0);
989 idx_begin_ = 0;
990 idx_end_ = 0;
991 full_ = false;
992 return;
993 }
994
995
997 // Growing
999 // Make SlidingBuffer indices equal to those of the underlying container
1000 std::rotate(storage_.begin(), storage_.begin() + static_cast<difference_type>(idx_begin_), storage_.end());
1001 storage_.resize(new_capacity);
1002 idx_begin_ = 0;
1003 idx_end_ = old_size;
1004 full_ = false;
1005 return;
1006 }
1007
1009 // Shrinking
1010 if (old_size < new_capacity) {
1011 // All data fits into new capacity, just move it there
1012 std::rotate(storage_.begin(), storage_.begin() + static_cast<difference_type>(idx_begin_), storage_.end());
1013 storage_.resize(new_capacity);
1014 idx_begin_ = 0;
1015 idx_end_ = old_size;
1016 full_ = false;
1017 }
1018 else {
1019 auto new_front = idx_begin_;
1020 if (shrink_behavior == ShrinkBehavior::keep_back_elements)
1022
1023 std::rotate(storage_.begin(), storage_.begin() + static_cast<difference_type>(new_front), storage_.end());
1024 storage_.resize(new_capacity);
1025 full_ = true;
1026 idx_begin_ = 0;
1027 idx_end_ = 0;
1028 }
1029 }
1030};
1031
1075template<typename ElementT, std::size_t fixed_capacity = 0u,
1076 typename Container = typename std::conditional_t<(fixed_capacity >= 1u),
1077 std::array<ElementT, fixed_capacity>,
1078 std::vector<ElementT>>
1079 >
1081public:
1083 using iterator = typename Container::iterator;
1085 using const_iterator = typename Container::const_iterator;
1087 using reverse_iterator = typename Container::reverse_iterator;
1089 using const_reverse_iterator = typename Container::const_reverse_iterator;
1090
1091 // Inherit member types
1100
1101 // Inherit constructors
1102 using SlidingBuffer<ElementT, fixed_capacity, Container>::SlidingBuffer;
1103
1104 // Inherit members for access without "this->"
1106 using SlidingBuffer<ElementT, fixed_capacity, Container>::idx_begin_;
1110
1125 {
1126 if (not full_ and (idx_end_ == 0 or idx_end_ >= idx_begin_))
1127 return storage_.begin() + static_cast<difference_type>(idx_begin_);
1128
1129 return storage_.begin();
1130 }
1131
1134 {
1135 return cbegin();
1136 }
1137
1145 {
1146 if (not full_ and (idx_end_ == 0 or idx_end_ >= idx_begin_))
1147 return storage_.cbegin() + idx_begin_;
1148
1149 return storage_.cbegin();
1150 }
1151
1170 {
1171 if (full_ or idx_begin_ != 0)
1172 return storage_.end();
1173
1174 return storage_.begin() + static_cast<difference_type>(idx_end_);
1175 }
1176
1179 {
1180 return cend();
1181 }
1182
1190 {
1191 if (full_ or idx_begin_ != 0)
1192 return storage_.cend();
1193
1194 return storage_.cbegin() + idx_end_;
1195 }
1196
1206 {
1207 return std::make_reverse_iterator(end());
1208 }
1209
1219 {
1220 return std::make_reverse_iterator(cend());
1221 }
1222
1229 {
1230 return std::make_reverse_iterator(begin());
1231 }
1232
1240 {
1241 return std::make_reverse_iterator(cbegin());
1242 }
1243
1263 auto resize(size_type new_capacity, ShrinkBehavior shrink_behavior = ShrinkBehavior::keep_front_elements) -> void
1264 {
1265 static_assert(fixed_capacity == 0u,
1266 "resize() only possible if the underlying container is resizable");
1267
1268 // We handle just one special case here: A pure right aligned un-full buffer
1269 //
1270 // I.e. only push_front() (not push_back()) has been used until now, and
1271 // the buffer is not yet filled completely. Then the data will only occupy
1272 // the 'right hand side' of the underlying container.
1273 //
1274 // In order to fulfill begin()'s and end()'s guarantee to include only
1275 // filled elements we need to right-align the data in the new container.
1276
1277 auto const old_capacity = capacity();
1278
1279 auto const right_align =
1280 (shrink_behavior == ShrinkBehavior::keep_front_elements)
1281 and (new_capacity > 0)
1283 and (not full_)
1284 and (idx_end_ == 0)
1285 and (idx_begin_ != 0);
1286
1287 if (not right_align)
1288 return this->change_capacity(new_capacity, shrink_behavior);
1289
1291 // Growing
1292 if (new_capacity > old_capacity) {
1293 storage_.resize(new_capacity);
1294 std::move_backward(storage_.begin() + static_cast<difference_type>(idx_begin_),
1295 storage_.begin() + static_cast<difference_type>(old_capacity), storage_.end());
1296 idx_begin_ += new_capacity - old_capacity;
1297 return;
1298 }
1299
1301 // Shrinking
1302 full_ = (this->size() >= new_capacity);
1303 auto const required_shift = std::min(old_capacity - new_capacity, idx_begin_);
1304 std::rotate(storage_.begin(), storage_.begin() + static_cast<difference_type>(required_shift), storage_.end());
1305 idx_begin_ -= required_shift;
1306 storage_.resize(new_capacity);
1307 }
1308
1313 auto reserve(size_type size, ShrinkBehavior shrink_behavior = ShrinkBehavior::keep_front_elements) -> void
1314 {
1315 static_assert(fixed_capacity == 0u,
1316 "reserve() only possible if the underlying container is resizable");
1317 resize(size, shrink_behavior);
1318 }
1319};
1320
1322
1323} // namespace gul17
1324
1325#endif
1326
1327// vi:ts=4:sw=4:sts=4:et
Declaration of the overload set for cat() and of the associated class ConvertingStringView.
A variant of SlidingBuffer that exposes the underlying container through its iterator interface.
Definition SlidingBuffer.h:1080
auto begin() noexcept -> iterator
Return an iterator to the first occupied element of the underlying container.
Definition SlidingBuffer.h:1124
typename Container::iterator iterator
Iterator to an element.
Definition SlidingBuffer.h:1083
auto end() const noexcept -> const_iterator
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:1178
typename Container::const_reverse_iterator const_reverse_iterator
Iterator to a const element in reversed container.
Definition SlidingBuffer.h:1089
auto crend() const noexcept -> const_reverse_iterator
Return a constant iterator to the last element of the reversed underlying container.
Definition SlidingBuffer.h:1239
auto cbegin() const noexcept -> const_iterator
Return a constant iterator to the first occupied element of the underlying container.
Definition SlidingBuffer.h:1144
auto cend() const noexcept -> const_iterator
Return a constant iterator to the element following the last element in the used space of the underly...
Definition SlidingBuffer.h:1189
auto crbegin() const noexcept -> const_reverse_iterator
Return a constant reverse iterator to the first used element of the reversed underlying container.
Definition SlidingBuffer.h:1218
auto rbegin() noexcept -> reverse_iterator
Return a reverse iterator to the first used element of the reversed underlying container.
Definition SlidingBuffer.h:1205
auto end() noexcept -> iterator
Return an iterator to the element following the last element in the used space of the underlying cont...
Definition SlidingBuffer.h:1169
auto rend() noexcept -> reverse_iterator
Return an iterator to the last element of the reversed underlying container.
Definition SlidingBuffer.h:1228
auto reserve(size_type size, ShrinkBehavior shrink_behavior=ShrinkBehavior::keep_front_elements) -> void
Resize the container (identical to resize()).
Definition SlidingBuffer.h:1313
typename Container::const_iterator const_iterator
Iterator to a const element.
Definition SlidingBuffer.h:1085
typename Container::reverse_iterator reverse_iterator
Iterator to an element in reversed container.
Definition SlidingBuffer.h:1087
auto begin() const noexcept -> const_iterator
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:1133
auto resize(size_type new_capacity, ShrinkBehavior shrink_behavior=ShrinkBehavior::keep_front_elements) -> void
Resize the container.
Definition SlidingBuffer.h:1263
Iterator of the SlidingBuffer container.
Definition SlidingBuffer.h:645
auto operator+=(difference_type d) noexcept -> SlidingBufferIterator &
Increase iterator by a given number of positions.
Definition SlidingBuffer.h:695
std::random_access_iterator_tag iterator_category
Defines the category of the iterator.
Definition SlidingBuffer.h:657
auto operator-=(difference_type d) noexcept -> SlidingBufferIterator &
Decrease iterator by a given number of positions.
Definition SlidingBuffer.h:733
SlidingBufferIterator(BufferPointer buff, size_type num=0) noexcept
Create an iterator pointing into a SlidingBuffer.
Definition SlidingBuffer.h:673
auto operator--(int) noexcept -> SlidingBufferIterator
Post-decrement iterator by one position.
Definition SlidingBuffer.h:725
friend auto operator+(difference_type d, const SlidingBufferIterator &it) noexcept -> SlidingBufferIterator
Add an integer and an iterator.
Definition SlidingBuffer.h:711
auto operator++(int) noexcept -> SlidingBufferIterator
Post-increment iterator by one position.
Definition SlidingBuffer.h:687
friend auto operator+(const SlidingBufferIterator &it, difference_type d) noexcept -> SlidingBufferIterator
Add an integer to an iterator.
Definition SlidingBuffer.h:703
value_type * pointer
This type represents a pointer-to-value_type.
Definition SlidingBuffer.h:663
friend auto operator>=(const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
Determine if the left iterator refers to position that is greater than or equal to than the right one...
Definition SlidingBuffer.h:826
friend auto operator>(const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
Determine if the left iterator refers to a greater position than the right one.
Definition SlidingBuffer.h:807
auto operator->() const noexcept -> typename std::conditional_t< std::is_const< std::remove_pointer_t< BufferPointer > >::value, const_pointer, pointer >
Access member of element pointed to by the iterator.
Definition SlidingBuffer.h:764
auto operator--() noexcept -> SlidingBufferIterator &
Pre-decrement iterator by one position.
Definition SlidingBuffer.h:718
ElementT value_type
The type "pointed to" by the iterator.
Definition SlidingBuffer.h:659
auto operator++() noexcept -> SlidingBufferIterator &
Pre-increment iterator by one position.
Definition SlidingBuffer.h:680
auto operator*() const noexcept -> typename std::conditional_t< std::is_const< std::remove_pointer_t< BufferPointer > >::value, const_reference, reference >
Access element pointed to by the iterator.
Definition SlidingBuffer.h:756
friend auto operator-(const SlidingBufferIterator &it, difference_type d) noexcept -> SlidingBufferIterator
Subtract an integer from an iterator.
Definition SlidingBuffer.h:741
friend auto operator-(const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> difference_type
Subtract two iterators.
Definition SlidingBuffer.h:749
friend auto operator==(const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
Compare two iterators for equality.
Definition SlidingBuffer.h:785
auto operator[](difference_type offs) noexcept -> typename std::conditional_t< std::is_const< std::remove_pointer_t< BufferPointer > >::value, const_reference, reference >
Dereference the iterator at a certain index offset.
Definition SlidingBuffer.h:772
friend auto operator!=(const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
Compare two iterators for inequality.
Definition SlidingBuffer.h:797
value_type & reference
This type represents a reference-to-value_type.
Definition SlidingBuffer.h:665
std::ptrdiff_t difference_type
Distance between iterators is represented as this type.
Definition SlidingBuffer.h:661
A circular data buffer of (semi-)fixed capacity to which elements can be added at the front or at the...
Definition SlidingBuffer.h:184
auto back() const noexcept -> const_reference
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:471
auto end() const noexcept -> const_iterator
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:882
auto crend() const noexcept -> const_reverse_iterator
Return a read-only iterator to the element following the last element of the reversed container.
Definition SlidingBuffer.h:938
Container container_type
Type of the underlying container (e.g. std::array<value_type, ..>)
Definition SlidingBuffer.h:189
auto push_back(const value_type &in) -> void
Insert one element at the end of the buffer; if it is full, an element at the front is dropped to mak...
Definition SlidingBuffer.h:309
SlidingBuffer(SlidingBuffer &&) noexcept(std::is_nothrow_move_constructible< container_type >::value)=default
Default move constructor.
SlidingBuffer()=default
Construct an empty sliding buffer.
auto operator[](size_type idx) noexcept -> reference
Access an element in the buffer by index without bounds checking.
Definition SlidingBuffer.h:384
typename Container::const_reference const_reference
Reference to a constant element.
Definition SlidingBuffer.h:199
auto rend() noexcept -> reverse_iterator
Return an iterator to the element following the last element of the reversed container.
Definition SlidingBuffer.h:894
typename Container::const_pointer const_pointer
Pointer to a constant element.
Definition SlidingBuffer.h:203
auto rbegin() noexcept -> reverse_iterator
Return an iterator to the first element of the reversed container.
Definition SlidingBuffer.h:865
auto clear() -> void
Empty the buffer.
Definition SlidingBuffer.h:529
auto resize(size_type new_capacity, ShrinkBehavior shrink_behavior=ShrinkBehavior::keep_front_elements) -> void
Resize the container.
Definition SlidingBuffer.h:558
auto begin() noexcept -> iterator
Return an iterator to the first element of the container.
Definition SlidingBuffer.h:849
auto push_front(const value_type &in) -> void
Insert one element at the front of the buffer; if it is full, an element at the back is dropped to ma...
Definition SlidingBuffer.h:347
auto cbegin() const noexcept -> const_iterator
Return a read-only iterator to the first element of the container.
Definition SlidingBuffer.h:904
std::reverse_iterator< iterator > reverse_iterator
Iterator to an element in reversed container.
Definition SlidingBuffer.h:209
typename Container::reference reference
Reference to an element.
Definition SlidingBuffer.h:197
auto back() noexcept -> reference
Return the backmost element (the one with the highest valid index).
Definition SlidingBuffer.h:460
auto pop_back() -> void
Remove the last element from the buffer.
Definition SlidingBuffer.h:273
auto size() const noexcept -> size_type
Return the number of elements in the container, i.e.
Definition SlidingBuffer.h:486
auto crbegin() const noexcept -> const_reverse_iterator
Return a read-only iterator to the first element of the reversed container.
Definition SlidingBuffer.h:914
typename Container::size_type size_type
Unsigned integer type (usually std::size_t)
Definition SlidingBuffer.h:193
auto cend() const noexcept -> const_iterator
Return a read-only iterator to the element following the last element of the container.
Definition SlidingBuffer.h:926
auto front() noexcept -> reference
Return the foremost element (the one with index 0).
Definition SlidingBuffer.h:441
auto empty() const noexcept -> bool
Check if the buffer contains no elements, i.e.
Definition SlidingBuffer.h:581
auto push_front(value_type &&in) -> void
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:362
auto at(const size_type idx) const noexcept(false) -> const_reference
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:425
auto constexpr capacity() const noexcept -> size_type
Return the maximum possible number of elements in the container.
Definition SlidingBuffer.h:504
ElementT value_type
Type of the elements in the underlying container.
Definition SlidingBuffer.h:191
auto end() noexcept -> iterator
Return an iterator to the element following the last element of the container.
Definition SlidingBuffer.h:876
auto reserve(size_type size, ShrinkBehavior shrink_behavior=ShrinkBehavior::keep_front_elements) -> void
Resize the container (identical to resize()).
Definition SlidingBuffer.h:569
auto change_capacity(size_type new_capacity, ShrinkBehavior shrink_behavior=ShrinkBehavior::keep_front_elements) -> void
Change the underlying container's capacity.
Definition SlidingBuffer.h:975
typename Container::difference_type difference_type
Signed integer type (usually std::ptrdiff_t)
Definition SlidingBuffer.h:195
auto operator[](size_type idx) const noexcept -> const_reference
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:394
SlidingBuffer(SlidingBuffer const &)=default
Default copy constructor.
auto filled() const noexcept -> bool
Return true if the buffer is completely filled with elements.
Definition SlidingBuffer.h:517
auto at(const size_type idx) noexcept(false) -> reference
Access an element in the buffer by index with bounds checking.
Definition SlidingBuffer.h:412
typename Container::pointer pointer
Pointer to an element.
Definition SlidingBuffer.h:201
auto pop_front() -> void
Remove the first element from the buffer.
Definition SlidingBuffer.h:290
std::reverse_iterator< const_iterator > const_reverse_iterator
Iterator to a const element in reversed container.
Definition SlidingBuffer.h:211
auto begin() const noexcept -> const_iterator
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:855
auto front() const noexcept -> const_reference
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:449
auto push_back(value_type &&in) -> void
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SlidingBuffer.h:323
ShrinkBehavior
Determine how a SlidingBuffer handles decreases of its size.
Definition SlidingBuffer.h:69
auto constexpr bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition bit_manip.h:124
std::string cat()
Efficiently concatenate an arbitrary number of strings and numbers.
Definition cat.h:100
Definition of macros used internally by GUL.
Namespace gul17 contains all functions and classes of the General Utility Library.
Definition doxygen.h:29