18#include <initializer_list>
27#include "lib/stdcompat/utility.h"
28#include "pw_assert/assert.h"
29#include "pw_containers/internal/deque_iterator.h"
30#include "pw_containers/internal/traits.h"
31#include "pw_containers/internal/wrap.h"
32#include "pw_numeric/checked_arithmetic.h"
33#include "pw_span/span.h"
35namespace pw::containers::internal {
38using EnableIfIterable =
39 std::enable_if_t<
true,
decltype(T().begin(), T().end())>;
55template <
typename CountAndCapacityType>
58 using size_type =
typename CountAndCapacityType::size_type;
62 [[nodiscard]]
constexpr bool empty()
const noexcept {
return size() == 0; }
64 [[nodiscard]]
constexpr bool full()
const noexcept {
69 constexpr size_type
size() const noexcept {
70 return count_and_capacity_.count();
74 constexpr size_type
capacity() const noexcept {
75 return count_and_capacity_.capacity();
81 CountAndCapacityType& count_and_capacity() noexcept {
82 return count_and_capacity_;
85 constexpr void MoveAssignIndices(GenericDequeBase& other)
noexcept {
86 count_and_capacity_ = std::move(other.count_and_capacity_);
87 head_ = cpp20::exchange(other.head_, 0);
88 tail_ = cpp20::exchange(other.tail_, 0);
91 void SwapIndices(GenericDequeBase& other)
noexcept {
92 std::swap(count_and_capacity_, other.count_and_capacity_);
93 std::swap(head_, other.head_);
94 std::swap(tail_, other.tail_);
99 bool CanExtendBuffer()
const {
return tail_ > head_ || tail_ == 0; }
102 bool CanShrinkBuffer()
const {
return head_ == 0; }
104 void HandleNewBuffer(size_type new_capacity) {
105 count_and_capacity_.SetCapacity(new_capacity);
107 tail_ =
size() == new_capacity
109 : count_and_capacity_.count();
112 void HandleExtendedBuffer(size_type new_capacity) {
113 count_and_capacity_.SetCapacity(new_capacity);
115 tail_ = head_ + count_and_capacity_.count();
119 void HandleShrunkBuffer(size_type new_capacity) {
120 count_and_capacity_.SetCapacity(new_capacity);
121 if (tail_ == new_capacity) {
128 template <
typename Derived,
typename ValueType,
typename S>
129 friend class GenericDeque;
131 explicit constexpr GenericDequeBase(size_type initial_capacity) noexcept
132 : count_and_capacity_(initial_capacity), head_(0), tail_(0) {}
134 constexpr void ClearIndices() {
135 count_and_capacity_.SetCount(0);
143 constexpr size_type AbsoluteIndex(
const size_type relative_index)
const {
144 const size_type absolute_index = head_ + relative_index;
146 return absolute_index;
152 constexpr size_type AbsoluteIndexChecked(
153 const size_type relative_index)
const {
154 PW_ASSERT(relative_index <
size());
155 return AbsoluteIndex(relative_index);
158 constexpr void PushBack(size_type count = 1) {
159 IncrementWithWrap(tail_, count,
capacity());
160 count_and_capacity_.IncrementCount(count);
162 constexpr void PushFront(size_type count = 1) {
163 DecrementWithWrap(head_, count,
capacity());
164 count_and_capacity_.IncrementCount(count);
166 constexpr void PopFront() {
167 IncrementWithWrap(head_, size_type(1),
capacity());
168 count_and_capacity_.DecrementCount();
170 constexpr void PopBack() {
171 DecrementWithWrap(tail_, size_type(1),
capacity());
172 count_and_capacity_.DecrementCount();
175 CountAndCapacityType count_and_capacity_;
184template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
190 using value_type = ValueType;
191 using size_type =
typename CountAndCapacityType::size_type;
192 using difference_type = ptrdiff_t;
193 using reference = value_type&;
194 using const_reference =
const value_type&;
195 using pointer = value_type*;
196 using const_pointer =
const value_type*;
197 using iterator = containers::internal::DequeIterator<Derived>;
198 using const_iterator = containers::internal::DequeIterator<const Derived>;
216 void assign(size_type count,
const value_type& value) {
222 template <
typename It,
224 typename = containers::internal::EnableIfInputIterator<It>>
228 void assign(
const std::initializer_list<value_type>& list) {
229 assign(list.begin(), list.end());
234 constexpr reference at(size_type index) {
235 return data()[Base::AbsoluteIndexChecked(index)];
237 constexpr const_reference at(size_type index)
const {
238 return data()[Base::AbsoluteIndexChecked(index)];
241 constexpr reference operator[](size_type index) {
242 PW_DASSERT(index <
size());
243 return data()[Base::AbsoluteIndex(index)];
245 constexpr const_reference operator[](size_type index)
const {
246 PW_DASSERT(index <
size());
247 return data()[Base::AbsoluteIndex(index)];
250 constexpr reference front() {
251 PW_DASSERT(!empty());
252 return data()[head()];
254 constexpr const_reference front()
const {
255 PW_DASSERT(!empty());
256 return data()[head()];
259 constexpr reference back() {
260 PW_DASSERT(!empty());
261 return data()[Base::AbsoluteIndex(
size() - 1)];
263 constexpr const_reference back()
const {
264 PW_DASSERT(!empty());
265 return data()[Base::AbsoluteIndex(
size() - 1)];
269 constexpr std::pair<span<const value_type>, span<const value_type>>
272 auto [first, second] = std::as_const(*this).contiguous_data();
273 return {{
const_cast<pointer
>(first.data()), first.size()},
274 {
const_cast<pointer
>(second.data()), second.size()}};
279 constexpr iterator begin() noexcept {
284 return iterator(derived(), 0);
286 constexpr const_iterator begin() const noexcept {
return cbegin(); }
287 constexpr const_iterator cbegin() const noexcept {
291 return const_iterator(derived(), 0);
294 constexpr iterator end() noexcept {
return iterator(derived(),
size()); }
295 constexpr const_iterator end() const noexcept {
return cend(); }
296 constexpr const_iterator cend() const noexcept {
297 return const_iterator(derived(),
size());
302 constexpr void clear() {
304 Base::ClearIndices();
308 iterator
erase(const_iterator pos) {
309 PW_DASSERT(pos.pos_ <
size());
310 return erase(pos, pos + 1);
315 iterator
erase(const_iterator first, const_iterator last);
317 void push_back(
const value_type& value) { PW_ASSERT(try_push_back(value)); }
319 void push_back(value_type&& value) {
320 PW_ASSERT(try_push_back(std::move(value)));
323 template <
typename... Args>
324 void emplace_back(Args&&... args) {
325 PW_ASSERT(try_emplace_back(std::forward<Args>(args)...));
330 void push_front(
const value_type& value) { PW_ASSERT(try_push_front(value)); }
332 void push_front(value_type&& value) {
333 PW_ASSERT(try_push_front(std::move(value)));
336 template <
typename... Args>
337 void emplace_front(Args&&... args) {
338 PW_ASSERT(try_emplace_front(std::forward<Args>(args)...));
347 template <
typename... Args>
348 iterator
emplace(const_iterator pos, Args&&... args) {
349 std::optional<iterator> result =
351 PW_ASSERT(result.has_value());
358 iterator
insert(const_iterator pos,
const value_type& value) {
359 std::optional<iterator> result =
try_insert(pos, value);
360 PW_ASSERT(result.has_value());
368 iterator
insert(const_iterator pos, value_type&& value) {
369 std::optional<iterator> result =
try_insert(pos, std::move(value));
370 PW_ASSERT(result.has_value());
380 const value_type& value) {
381 std::optional<iterator> result =
try_insert(pos, count, value);
382 PW_ASSERT(result.has_value());
390 template <
typename InputIt,
391 typename = containers::internal::EnableIfInputIterator<InputIt>>
392 iterator
insert(const_iterator pos, InputIt first, InputIt last);
397 iterator
insert(const_iterator pos, std::initializer_list<value_type> ilist) {
398 std::optional<iterator> result =
try_insert(pos, ilist);
399 PW_ASSERT(result.has_value());
403 void resize(size_type new_size) { resize(new_size, value_type()); }
405 void resize(size_type new_size,
const value_type& value) {
406 PW_ASSERT(try_resize(new_size, value));
410 explicit constexpr GenericDeque(size_type initial_capacity) noexcept
411 : GenericDequeBase<CountAndCapacityType>(initial_capacity) {}
413 constexpr void DestroyAll() {
414 if constexpr (!std::is_trivially_destructible_v<value_type>) {
415 std::destroy(begin(), end());
422 Derived& operator=(
const std::initializer_list<value_type>& list) {
427 template <
typename T,
typename = containers::
internal::EnableIfIterable<T>>
428 Derived& operator=(
const T& other) {
429 assign(other.begin(), other.end());
439 [[nodiscard]]
bool try_assign(size_type count,
const value_type& value);
447 template <
typename It,
449 typename = containers::internal::EnableIfForwardIterator<It>>
454 [[nodiscard]]
bool try_assign(
const std::initializer_list<value_type>& list) {
465 template <
typename... Args>
466 [[nodiscard]] std::optional<iterator>
try_emplace(const_iterator pos,
474 [[nodiscard]] std::optional<iterator>
try_insert(const_iterator pos,
475 const value_type& value) {
484 [[nodiscard]] std::optional<iterator>
try_insert(const_iterator pos,
485 value_type&& value) {
494 [[nodiscard]] std::optional<iterator>
try_insert(const_iterator pos,
496 const value_type& value);
503 template <
typename ForwardIt,
504 typename = containers::internal::EnableIfForwardIterator<ForwardIt>>
505 [[nodiscard]] std::optional<iterator>
try_insert(const_iterator pos,
515 const_iterator pos, std::initializer_list<value_type> ilist) {
516 return try_insert(pos, ilist.begin(), ilist.end());
519 [[nodiscard]]
bool try_push_back(
const value_type& value) {
520 return try_emplace_back(value);
523 [[nodiscard]]
bool try_push_back(value_type&& value) {
524 return try_emplace_back(std::move(value));
527 template <
typename... Args>
528 [[nodiscard]]
bool try_emplace_back(Args&&... args);
530 [[nodiscard]]
bool try_push_front(
const value_type& value) {
531 return try_emplace_front(value);
534 [[nodiscard]]
bool try_push_front(value_type&& value) {
535 return try_emplace_front(std::move(value));
538 template <
typename... Args>
539 [[nodiscard]]
bool try_emplace_front(Args&&... args);
541 [[nodiscard]]
bool try_resize(size_type new_size) {
542 return try_resize(new_size, value_type());
545 [[nodiscard]]
bool try_resize(size_type new_size,
const value_type& value);
547 template <
typename... Args>
548 [[nodiscard]] std::optional<iterator> try_emplace_shift_right(
549 const_iterator pos, Args&&... args);
551 [[nodiscard]] std::optional<iterator> try_insert_shift_right(
552 const_iterator pos, size_type count,
const value_type& value);
554 template <
typename ForwardIt,
555 typename = containers::internal::EnableIfForwardIterator<ForwardIt>>
556 [[nodiscard]] std::optional<iterator> try_insert_shift_right(
557 const_iterator pos, ForwardIt first, ForwardIt last);
560 constexpr Derived& derived() {
return static_cast<Derived&
>(*this); }
561 constexpr const Derived& derived()
const {
562 return static_cast<const Derived&
>(*this);
565 constexpr size_type head()
const {
return Base::head_; }
566 constexpr size_type tail()
const {
return Base::tail_; }
569 constexpr pointer data() {
return derived().data(); }
570 constexpr const_pointer data()
const {
return derived().data(); }
573 bool ShiftForInsert(size_type insert_index, size_type new_items);
576 void ShiftLeft(size_type insert_index, size_type new_items);
577 void ShiftRight(size_type insert_index, size_type new_items);
580 bool CheckCapacityAdd(size_type count) {
582 return CheckedAdd(
size(), count, new_size) && CheckCapacity(new_size);
586 constexpr bool CheckCapacity(size_type new_size) {
587 if constexpr (Derived::kFixedCapacity) {
590 return derived().try_reserve(new_size);
595 template <
typename... Args>
596 void EmplaceBackUnchecked(Args&&... args) {
597 new (&data()[tail()]) value_type(std::forward<Args>(args)...);
604template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
605template <
typename It,
int&...,
typename>
609 if constexpr (Derived::kFixedCapacity ||
611 typename std::iterator_traits<It>::iterator_category,
612 std::input_iterator_tag>) {
614 while (start != finish) {
619 PW_ASSERT(try_assign(start, finish));
623template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
625 size_type count,
const value_type& value) {
626 if (!CheckCapacity(count)) {
630 Base::PushBack(count);
631 std::uninitialized_fill_n(data(), count, value);
635template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
636template <
typename It,
int&...,
typename>
638 It start, It finish) {
640 static_assert(std::is_convertible_v<
641 typename std::iterator_traits<It>::iterator_category,
642 std::forward_iterator_tag>);
643 const auto items = std::distance(start, finish);
644 PW_DASSERT(items >= 0);
645 if (
static_cast<std::make_unsigned_t<decltype(items)
>>(items) >
646 std::numeric_limits<size_type>::max()) {
649 const size_type count =
static_cast<size_type
>(items);
650 if (!CheckCapacity(count)) {
655 Base::PushBack(count);
656 std::uninitialized_move(start, finish, data());
660template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
667 if (tail() > head()) {
681template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
682template <
typename... Args>
685 if (!CheckCapacityAdd(1)) {
688 EmplaceBackUnchecked(std::forward<Args>(args)...);
692template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
693void GenericDeque<Derived, ValueType, CountAndCapacityType>::pop_back() {
695 if constexpr (!std::is_trivially_destructible_v<value_type>) {
696 std::destroy_at(&back());
701template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
702template <
typename... Args>
703bool GenericDeque<Derived, ValueType, CountAndCapacityType>::try_emplace_front(
705 if (!CheckCapacityAdd(1)) {
709 new (&data()[head()]) value_type(std::forward<Args>(args)...);
713template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
714void GenericDeque<Derived, ValueType, CountAndCapacityType>::pop_front() {
716 if constexpr (!std::is_trivially_destructible_v<value_type>) {
717 std::destroy_at(&front());
722template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
723bool GenericDeque<Derived, ValueType, CountAndCapacityType>::try_resize(
724 size_type new_size,
const value_type& value) {
725 if (size() < new_size) {
726 if (!CheckCapacity(new_size)) {
729 const size_type new_items = new_size - size();
730 for (size_type i = 0; i < new_items; ++i) {
731 EmplaceBackUnchecked(value);
734 while (size() > new_size) {
741template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
742typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator
744 const_iterator first, const_iterator last) {
745 PW_DASSERT(first <= last);
746 const iterator first_it(derived(), first.pos_);
747 const iterator last_it(derived(), last.pos_);
749 const size_type items_to_erase =
static_cast<size_type
>(last - first);
750 if (items_to_erase == 0) {
754 const size_type items_after =
static_cast<size_type
>(size() - last.pos_);
756 if (first.pos_ < items_after) {
757 std::move_backward(begin(), first_it, last_it);
758 if constexpr (!std::is_trivially_destructible_v<value_type>) {
759 std::destroy(begin(), begin() + items_to_erase);
761 Base::head_ = Base::AbsoluteIndex(items_to_erase);
763 std::move(last_it, end(), first_it);
764 if constexpr (!std::is_trivially_destructible_v<value_type>) {
765 std::destroy(first_it + items_after, end());
767 Base::tail_ = Base::AbsoluteIndex(first.pos_ + items_after);
769 Base::count_and_capacity().SetCount(size() - items_to_erase);
773template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
774template <
typename... Args>
776 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
778 const_iterator pos, Args&&... args) {
780 if (!ShiftForInsert(pos.pos_, 1)) {
783 iterator it(derived(), pos.pos_);
784 new (std::addressof(*it)) value_type(std::forward<Args>(args)...);
788template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
789bool GenericDeque<Derived, ValueType, CountAndCapacityType>::ShiftForInsert(
790 const size_type insert_index, size_type new_items) {
791 if (!CheckCapacityAdd(new_items)) {
795 if (insert_index < size() / 2) {
796 ShiftLeft(insert_index, new_items);
798 ShiftRight(insert_index, new_items);
803template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
804void GenericDeque<Derived, ValueType, CountAndCapacityType>::ShiftLeft(
805 const size_type insert_index, size_type new_items) {
806 Base::PushFront(new_items);
807 iterator original_begin(derived(), new_items);
809 const size_type move_to_new_slots = std::min(new_items, insert_index);
810 auto [next_src, next_dst] =
811 std::uninitialized_move_n(original_begin, move_to_new_slots, begin());
813 const size_type move_to_existing_slots = insert_index - move_to_new_slots;
814 std::move(next_src, next_src + move_to_existing_slots, next_dst);
819 if constexpr (!std::is_trivially_destructible_v<value_type>) {
821 iterator(derived(), std::max(insert_index, original_begin.pos_)),
822 iterator(derived(), insert_index + new_items));
826template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
827void GenericDeque<Derived, ValueType, CountAndCapacityType>::ShiftRight(
828 const size_type insert_index, size_type new_items) {
829 const size_type items_after = size() - insert_index;
830 iterator original_end = end();
831 Base::PushBack(new_items);
833 const size_type move_to_new_slots = std::min(new_items, items_after);
834 std::uninitialized_move(original_end - move_to_new_slots,
836 end() - move_to_new_slots);
838 const size_type move_to_existing_slots = items_after - move_to_new_slots;
839 iterator pos(derived(), insert_index);
840 std::move_backward(pos, pos + move_to_existing_slots, original_end);
845 if constexpr (!std::is_trivially_destructible_v<value_type>) {
847 iterator(derived(), insert_index),
849 std::min(
static_cast<size_type
>(insert_index + new_items),
850 original_end.pos_)));
854template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
856 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
858 const_iterator pos, size_type count,
const value_type& value) {
860 return iterator(derived(), pos.pos_);
862 if (!ShiftForInsert(pos.pos_, count)) {
866 iterator it(derived(), pos.pos_);
867 std::uninitialized_fill_n(it, count, value);
871template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
872template <
typename InputIt,
typename>
873typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator
875 const_iterator pos, InputIt first, InputIt last) {
877 if constexpr (std::is_same_v<
878 typename std::iterator_traits<InputIt>::iterator_category,
879 std::input_iterator_tag>) {
882 iterator insert_pos = iterator(derived(), pos.pos_);
883 while (first != last) {
884 insert_pos = emplace(insert_pos, *first);
888 return iterator(derived(), pos.pos_);
890 std::optional<iterator> result = try_insert(pos, first, last);
891 PW_ASSERT(result.has_value());
896template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
897template <
typename ForwardIt,
typename>
899 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
901 const_iterator pos, ForwardIt first, ForwardIt last) {
902 static_assert(std::is_convertible_v<
903 typename std::iterator_traits<ForwardIt>::iterator_category,
904 std::forward_iterator_tag>);
905 const auto distance = std::distance(first, last);
906 PW_DASSERT(distance >= 0);
907 const size_type count =
static_cast<size_type
>(distance);
909 const iterator it(derived(), pos.pos_);
913 if (!ShiftForInsert(pos.pos_, count)) {
916 std::uninitialized_move(first, last, it);
920template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
921template <
typename... Args>
923 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
924GenericDeque<Derived, ValueType, CountAndCapacityType>::try_emplace_shift_right(
925 const_iterator pos, Args&&... args) {
926 if (!CheckCapacityAdd(1)) {
929 ShiftRight(pos.pos_, 1);
930 iterator it(derived(), pos.pos_);
931 new (std::addressof(*it)) value_type(std::forward<Args>(args)...);
935template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
937 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
938GenericDeque<Derived, ValueType, CountAndCapacityType>::try_insert_shift_right(
939 const_iterator pos, size_type count,
const value_type& value) {
941 return iterator(derived(), pos.pos_);
943 if (!CheckCapacityAdd(count)) {
947 ShiftRight(pos.pos_, count);
948 iterator it(derived(), pos.pos_);
949 std::uninitialized_fill_n(it, count, value);
953template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
954template <
typename ForwardIt,
typename>
956 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
957GenericDeque<Derived, ValueType, CountAndCapacityType>::try_insert_shift_right(
958 const_iterator pos, ForwardIt first, ForwardIt last) {
959 static_assert(std::is_convertible_v<
960 typename std::iterator_traits<ForwardIt>::iterator_category,
961 std::forward_iterator_tag>);
962 const auto distance = std::distance(first, last);
963 PW_DASSERT(distance >= 0);
964 const size_type count =
static_cast<size_type
>(distance);
966 const iterator it(derived(), pos.pos_);
970 if (!CheckCapacityAdd(count)) {
973 ShiftRight(pos.pos_, count);
974 std::uninitialized_move(first, last, it);
Definition: generic_deque.h:56
Definition: generic_deque.h:185
constexpr size_type size() const noexcept
Returns the number of elements in the deque.
Definition: generic_deque.h:69
constexpr size_type capacity() const noexcept
Returns the maximum number of elements in the deque.
Definition: generic_deque.h:74
Definition: span_impl.h:235
constexpr size_type size() const noexcept
Returns the number of elements in the deque.
Definition: generic_deque.h:69
iterator insert(const_iterator pos, size_type count, const value_type &value)
Definition: generic_deque.h:378
constexpr std::pair< span< const value_type >, span< const value_type > > contiguous_data() const
Provides access to the valid data in a contiguous form.
Definition: generic_deque.h:662
std::optional< iterator > try_insert(const_iterator pos, std::initializer_list< value_type > ilist)
Definition: generic_deque.h:514
bool try_assign(size_type count, const value_type &value)
Definition: generic_deque.h:624
void assign(const std::initializer_list< value_type > &list)
Sets contents to copies of the items from the list. Crashes if cannot fit.
Definition: generic_deque.h:228
iterator insert(const_iterator pos, const value_type &value)
Definition: generic_deque.h:358
void assign(It start, It finish)
Definition: generic_deque.h:606
iterator erase(const_iterator first, const_iterator last)
Definition: generic_deque.h:743
std::optional< iterator > try_emplace(const_iterator pos, Args &&... args)
bool try_assign(const std::initializer_list< value_type > &list)
Definition: generic_deque.h:454
iterator emplace(const_iterator pos, Args &&... args)
Definition: generic_deque.h:348
iterator erase(const_iterator pos)
Erases the item at pos, which must be a dereferenceable iterator.
Definition: generic_deque.h:308
iterator insert(const_iterator pos, InputIt first, InputIt last)
Definition: generic_deque.h:874
constexpr size_type capacity() const noexcept
Returns the maximum number of elements in the deque.
Definition: generic_deque.h:74
std::optional< iterator > try_insert(const_iterator pos, const value_type &value)
Definition: generic_deque.h:474
std::optional< iterator > try_insert(const_iterator pos, value_type &&value)
Definition: generic_deque.h:484
void assign(size_type count, const value_type &value)
Sets the contents to count copies of value. Crashes if cannot fit.
Definition: generic_deque.h:216
iterator insert(const_iterator pos, value_type &&value)
Definition: generic_deque.h:368
std::optional< iterator > try_insert(const_iterator pos, ForwardIt first, ForwardIt last)
iterator insert(const_iterator pos, std::initializer_list< value_type > ilist)
Definition: generic_deque.h:397
constexpr bool CheckedAdd(A a, B b, T &result)
Definition: checked_arithmetic.h:70