18#include <initializer_list>
27#include "pw_assert/assert.h"
28#include "pw_containers/internal/deque_iterator.h"
29#include "pw_containers/internal/traits.h"
30#include "pw_containers/internal/wrap.h"
31#include "pw_numeric/checked_arithmetic.h"
32#include "pw_span/span.h"
34namespace pw::containers::internal {
37using EnableIfIterable =
38 std::enable_if_t<
true,
decltype(T().begin(), T().end())>;
54template <
typename CountAndCapacityType>
57 using size_type =
typename CountAndCapacityType::size_type;
61 [[nodiscard]]
constexpr bool empty()
const noexcept {
return size() == 0; }
64 constexpr size_type
size() const noexcept {
65 return count_and_capacity_.count();
69 constexpr size_type
capacity() const noexcept {
70 return count_and_capacity_.capacity();
76 CountAndCapacityType& count_and_capacity() noexcept {
77 return count_and_capacity_;
80 constexpr void MoveAssignIndices(GenericDequeBase& other)
noexcept {
81 count_and_capacity_ = std::move(other.count_and_capacity_);
82 head_ = std::exchange(other.head_, 0);
83 tail_ = std::exchange(other.tail_, 0);
86 void SwapIndices(GenericDequeBase& other)
noexcept {
87 std::swap(count_and_capacity_, other.count_and_capacity_);
88 std::swap(head_, other.head_);
89 std::swap(tail_, other.tail_);
94 bool CanExtendBuffer()
const {
return tail_ > head_ || tail_ == 0; }
97 bool CanShrinkBuffer()
const {
return head_ == 0; }
99 void HandleNewBuffer(size_type new_capacity) {
100 count_and_capacity_.SetCapacity(new_capacity);
102 tail_ =
size() == new_capacity
104 : count_and_capacity_.count();
107 void HandleExtendedBuffer(size_type new_capacity) {
108 count_and_capacity_.SetCapacity(new_capacity);
110 tail_ = head_ + count_and_capacity_.count();
114 void HandleShrunkBuffer(size_type new_capacity) {
115 count_and_capacity_.SetCapacity(new_capacity);
116 if (tail_ == new_capacity) {
123 template <
typename Derived,
typename ValueType,
typename S>
124 friend class GenericDeque;
126 explicit constexpr GenericDequeBase(size_type initial_capacity) noexcept
127 : count_and_capacity_(initial_capacity), head_(0), tail_(0) {}
129 constexpr void ClearIndices() {
130 count_and_capacity_.SetCount(0);
138 constexpr size_type AbsoluteIndex(
const size_type relative_index)
const {
139 const size_type absolute_index = head_ + relative_index;
141 return absolute_index;
147 constexpr size_type AbsoluteIndexChecked(
148 const size_type relative_index)
const {
149 PW_ASSERT(relative_index <
size());
150 return AbsoluteIndex(relative_index);
153 constexpr void PushBack(size_type count = 1) {
154 IncrementWithWrap(tail_, count,
capacity());
155 count_and_capacity_.IncrementCount(count);
157 constexpr void PushFront(size_type count = 1) {
158 DecrementWithWrap(head_, count,
capacity());
159 count_and_capacity_.IncrementCount(count);
161 constexpr void PopFront() {
162 IncrementWithWrap(head_, size_type(1),
capacity());
163 count_and_capacity_.DecrementCount();
165 constexpr void PopBack() {
166 DecrementWithWrap(tail_, size_type(1),
capacity());
167 count_and_capacity_.DecrementCount();
170 CountAndCapacityType count_and_capacity_;
179template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
185 using value_type = ValueType;
186 using size_type =
typename CountAndCapacityType::size_type;
187 using difference_type = ptrdiff_t;
188 using reference = value_type&;
189 using const_reference =
const value_type&;
190 using pointer = value_type*;
191 using const_pointer =
const value_type*;
192 using iterator = containers::internal::DequeIterator<Derived>;
193 using const_iterator = containers::internal::DequeIterator<const Derived>;
211 void assign(size_type count,
const value_type& value) {
217 template <
typename It,
219 typename = containers::internal::EnableIfInputIterator<It>>
223 void assign(
const std::initializer_list<value_type>& list) {
224 assign(list.begin(), list.end());
229 constexpr reference at(size_type index) {
230 return data()[Base::AbsoluteIndexChecked(index)];
232 constexpr const_reference at(size_type index)
const {
233 return data()[Base::AbsoluteIndexChecked(index)];
236 constexpr reference operator[](size_type index) {
237 PW_DASSERT(index <
size());
238 return data()[Base::AbsoluteIndex(index)];
240 constexpr const_reference operator[](size_type index)
const {
241 PW_DASSERT(index <
size());
242 return data()[Base::AbsoluteIndex(index)];
245 constexpr reference front() {
246 PW_DASSERT(!empty());
247 return data()[head()];
249 constexpr const_reference front()
const {
250 PW_DASSERT(!empty());
251 return data()[head()];
254 constexpr reference back() {
255 PW_DASSERT(!empty());
256 return data()[Base::AbsoluteIndex(
size() - 1)];
258 constexpr const_reference back()
const {
259 PW_DASSERT(!empty());
260 return data()[Base::AbsoluteIndex(
size() - 1)];
264 constexpr std::pair<span<const value_type>, span<const value_type>>
267 auto [first, second] = std::as_const(*this).contiguous_data();
268 return {{
const_cast<pointer
>(first.data()), first.size()},
269 {
const_cast<pointer
>(second.data()), second.size()}};
274 constexpr iterator begin() noexcept {
279 return iterator(derived(), 0);
281 constexpr const_iterator begin() const noexcept {
return cbegin(); }
282 constexpr const_iterator cbegin() const noexcept {
286 return const_iterator(derived(), 0);
289 constexpr iterator end() noexcept {
return iterator(derived(),
size()); }
290 constexpr const_iterator end() const noexcept {
return cend(); }
291 constexpr const_iterator cend() const noexcept {
292 return const_iterator(derived(),
size());
298 if constexpr (!std::is_trivially_destructible_v<value_type>) {
299 std::destroy(begin(), end());
301 Base::ClearIndices();
305 iterator
erase(const_iterator pos) {
306 PW_DASSERT(pos.pos_ <
size());
307 return erase(pos, pos + 1);
312 iterator
erase(const_iterator first, const_iterator last);
314 void push_back(
const value_type& value) { PW_ASSERT(try_push_back(value)); }
316 void push_back(value_type&& value) {
317 PW_ASSERT(try_push_back(std::move(value)));
320 template <
typename... Args>
321 void emplace_back(Args&&... args) {
322 PW_ASSERT(try_emplace_back(std::forward<Args>(args)...));
327 void push_front(
const value_type& value) { PW_ASSERT(try_push_front(value)); }
329 void push_front(value_type&& value) {
330 PW_ASSERT(try_push_front(std::move(value)));
333 template <
typename... Args>
334 void emplace_front(Args&&... args) {
335 PW_ASSERT(try_emplace_front(std::forward<Args>(args)...));
344 template <
typename... Args>
345 iterator
emplace(const_iterator pos, Args&&... args) {
346 std::optional<iterator> result =
348 PW_ASSERT(result.has_value());
355 iterator
insert(const_iterator pos,
const value_type& value) {
356 std::optional<iterator> result =
try_insert(pos, value);
357 PW_ASSERT(result.has_value());
365 iterator
insert(const_iterator pos, value_type&& value) {
366 std::optional<iterator> result =
try_insert(pos, std::move(value));
367 PW_ASSERT(result.has_value());
377 const value_type& value) {
378 std::optional<iterator> result =
try_insert(pos, count, value);
379 PW_ASSERT(result.has_value());
387 template <
typename InputIt,
388 typename = containers::internal::EnableIfInputIterator<InputIt>>
389 iterator
insert(const_iterator pos, InputIt first, InputIt last);
394 iterator
insert(const_iterator pos, std::initializer_list<value_type> ilist) {
395 std::optional<iterator> result =
try_insert(pos, ilist);
396 PW_ASSERT(result.has_value());
400 void resize(size_type new_size) { resize(new_size, value_type()); }
402 void resize(size_type new_size,
const value_type& value) {
403 PW_ASSERT(try_resize(new_size, value));
407 explicit constexpr GenericDeque(size_type initial_capacity) noexcept
408 : GenericDequeBase<CountAndCapacityType>(initial_capacity) {}
413 Derived& operator=(
const std::initializer_list<value_type>& list) {
418 template <
typename T,
typename = containers::
internal::EnableIfIterable<T>>
419 Derived& operator=(
const T& other) {
420 assign(other.begin(), other.end());
430 [[nodiscard]]
bool try_assign(size_type count,
const value_type& value);
438 template <
typename It,
440 typename = containers::internal::EnableIfForwardIterator<It>>
445 [[nodiscard]]
bool try_assign(
const std::initializer_list<value_type>& list) {
456 template <
typename... Args>
457 [[nodiscard]] std::optional<iterator>
try_emplace(const_iterator pos,
465 [[nodiscard]] std::optional<iterator>
try_insert(const_iterator pos,
466 const value_type& value) {
475 [[nodiscard]] std::optional<iterator>
try_insert(const_iterator pos,
476 value_type&& value) {
485 [[nodiscard]] std::optional<iterator>
try_insert(const_iterator pos,
487 const value_type& value);
494 template <
typename ForwardIt,
495 typename = containers::internal::EnableIfForwardIterator<ForwardIt>>
496 [[nodiscard]] std::optional<iterator>
try_insert(const_iterator pos,
506 const_iterator pos, std::initializer_list<value_type> ilist) {
507 return try_insert(pos, ilist.begin(), ilist.end());
510 [[nodiscard]]
bool try_push_back(
const value_type& value) {
511 return try_emplace_back(value);
514 [[nodiscard]]
bool try_push_back(value_type&& value) {
515 return try_emplace_back(std::move(value));
518 template <
typename... Args>
519 [[nodiscard]]
bool try_emplace_back(Args&&... args);
521 [[nodiscard]]
bool try_push_front(
const value_type& value) {
522 return try_emplace_front(value);
525 [[nodiscard]]
bool try_push_front(value_type&& value) {
526 return try_emplace_front(std::move(value));
529 template <
typename... Args>
530 [[nodiscard]]
bool try_emplace_front(Args&&... args);
532 [[nodiscard]]
bool try_resize(size_type new_size) {
533 return try_resize(new_size, value_type());
536 [[nodiscard]]
bool try_resize(size_type new_size,
const value_type& value);
538 template <
typename... Args>
539 [[nodiscard]] std::optional<iterator> try_emplace_shift_right(
540 const_iterator pos, Args&&... args);
542 [[nodiscard]] std::optional<iterator> try_insert_shift_right(
543 const_iterator pos, size_type count,
const value_type& value);
545 template <
typename ForwardIt,
546 typename = containers::internal::EnableIfForwardIterator<ForwardIt>>
547 [[nodiscard]] std::optional<iterator> try_insert_shift_right(
548 const_iterator pos, ForwardIt first, ForwardIt last);
551 constexpr Derived& derived() {
return static_cast<Derived&
>(*this); }
552 constexpr const Derived& derived()
const {
553 return static_cast<const Derived&
>(*this);
556 constexpr size_type head()
const {
return Base::head_; }
557 constexpr size_type tail()
const {
return Base::tail_; }
560 constexpr pointer data() {
return derived().data(); }
561 constexpr const_pointer data()
const {
return derived().data(); }
564 bool ShiftForInsert(size_type insert_index, size_type new_items);
567 void ShiftLeft(size_type insert_index, size_type new_items);
568 void ShiftRight(size_type insert_index, size_type new_items);
571 bool CheckCapacityAdd(size_type count) {
573 return CheckedAdd(
size(), count, new_size) && CheckCapacity(new_size);
577 constexpr bool CheckCapacity(size_type new_size) {
578 if constexpr (Derived::kFixedCapacity) {
581 return derived().try_reserve(new_size);
586 template <
typename... Args>
587 void EmplaceBackUnchecked(Args&&... args) {
588 new (&data()[tail()]) value_type(std::forward<Args>(args)...);
595template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
596template <
typename It,
int&...,
typename>
600 if constexpr (Derived::kFixedCapacity ||
602 typename std::iterator_traits<It>::iterator_category,
603 std::input_iterator_tag>) {
605 while (start != finish) {
610 PW_ASSERT(try_assign(start, finish));
614template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
616 size_type count,
const value_type& value) {
617 if (!CheckCapacity(count)) {
621 Base::PushBack(count);
622 std::uninitialized_fill_n(data(), count, value);
626template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
627template <
typename It,
int&...,
typename>
629 It start, It finish) {
631 static_assert(std::is_convertible_v<
632 typename std::iterator_traits<It>::iterator_category,
633 std::forward_iterator_tag>);
634 const auto items = std::distance(start, finish);
635 PW_DASSERT(items >= 0);
636 if (
static_cast<std::make_unsigned_t<decltype(items)
>>(items) >
637 std::numeric_limits<size_type>::max()) {
640 const size_type count =
static_cast<size_type
>(items);
641 if (!CheckCapacity(count)) {
646 Base::PushBack(count);
647 std::uninitialized_move(start, finish, data());
651template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
658 if (tail() > head()) {
672template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
673template <
typename... Args>
676 if (!CheckCapacityAdd(1)) {
679 EmplaceBackUnchecked(std::forward<Args>(args)...);
683template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
684void GenericDeque<Derived, ValueType, CountAndCapacityType>::pop_back() {
686 if constexpr (!std::is_trivially_destructible_v<value_type>) {
687 std::destroy_at(&back());
692template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
693template <
typename... Args>
694bool GenericDeque<Derived, ValueType, CountAndCapacityType>::try_emplace_front(
696 if (!CheckCapacityAdd(1)) {
700 new (&data()[head()]) value_type(std::forward<Args>(args)...);
704template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
705void GenericDeque<Derived, ValueType, CountAndCapacityType>::pop_front() {
707 if constexpr (!std::is_trivially_destructible_v<value_type>) {
708 std::destroy_at(&front());
713template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
714bool GenericDeque<Derived, ValueType, CountAndCapacityType>::try_resize(
715 size_type new_size,
const value_type& value) {
716 if (size() < new_size) {
717 if (!CheckCapacity(new_size)) {
720 const size_type new_items = new_size - size();
721 for (size_type i = 0; i < new_items; ++i) {
722 EmplaceBackUnchecked(value);
725 while (size() > new_size) {
732template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
733typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator
735 const_iterator first, const_iterator last) {
736 PW_DASSERT(first <= last);
737 const iterator first_it(derived(), first.pos_);
738 const iterator last_it(derived(), last.pos_);
740 const size_type items_to_erase =
static_cast<size_type
>(last - first);
741 if (items_to_erase == 0) {
745 const size_type items_after =
static_cast<size_type
>(size() - last.pos_);
747 if (first.pos_ < items_after) {
748 std::move_backward(begin(), first_it, last_it);
749 if constexpr (!std::is_trivially_destructible_v<value_type>) {
750 std::destroy(begin(), begin() + items_to_erase);
752 Base::head_ = Base::AbsoluteIndex(items_to_erase);
754 std::move(last_it, end(), first_it);
755 if constexpr (!std::is_trivially_destructible_v<value_type>) {
756 std::destroy(first_it + items_after, end());
758 Base::tail_ = Base::AbsoluteIndex(first.pos_ + items_after);
760 Base::count_and_capacity().SetCount(size() - items_to_erase);
764template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
765template <
typename... Args>
767 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
769 const_iterator pos, Args&&... args) {
771 if (!ShiftForInsert(pos.pos_, 1)) {
774 iterator it(derived(), pos.pos_);
775 new (std::addressof(*it)) value_type(std::forward<Args>(args)...);
779template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
780bool GenericDeque<Derived, ValueType, CountAndCapacityType>::ShiftForInsert(
781 const size_type insert_index, size_type new_items) {
782 if (!CheckCapacityAdd(new_items)) {
786 if (insert_index < size() / 2) {
787 ShiftLeft(insert_index, new_items);
789 ShiftRight(insert_index, new_items);
794template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
795void GenericDeque<Derived, ValueType, CountAndCapacityType>::ShiftLeft(
796 const size_type insert_index, size_type new_items) {
797 Base::PushFront(new_items);
798 iterator original_begin(derived(), new_items);
800 const size_type move_to_new_slots = std::min(new_items, insert_index);
801 auto [next_src, next_dst] =
802 std::uninitialized_move_n(original_begin, move_to_new_slots, begin());
804 const size_type move_to_existing_slots = insert_index - move_to_new_slots;
805 std::move(next_src, next_src + move_to_existing_slots, next_dst);
810 if constexpr (!std::is_trivially_destructible_v<value_type>) {
812 iterator(derived(), std::max(insert_index, original_begin.pos_)),
813 iterator(derived(), insert_index + new_items));
817template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
818void GenericDeque<Derived, ValueType, CountAndCapacityType>::ShiftRight(
819 const size_type insert_index, size_type new_items) {
820 const size_type items_after = size() - insert_index;
821 iterator original_end = end();
822 Base::PushBack(new_items);
824 const size_type move_to_new_slots = std::min(new_items, items_after);
825 std::uninitialized_move(original_end - move_to_new_slots,
827 end() - move_to_new_slots);
829 const size_type move_to_existing_slots = items_after - move_to_new_slots;
830 iterator pos(derived(), insert_index);
831 std::move_backward(pos, pos + move_to_existing_slots, original_end);
836 if constexpr (!std::is_trivially_destructible_v<value_type>) {
838 iterator(derived(), insert_index),
840 std::min(
static_cast<size_type
>(insert_index + new_items),
841 original_end.pos_)));
845template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
847 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
849 const_iterator pos, size_type count,
const value_type& value) {
851 return iterator(derived(), pos.pos_);
853 if (!ShiftForInsert(pos.pos_, count)) {
857 iterator it(derived(), pos.pos_);
858 std::uninitialized_fill_n(it, count, value);
862template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
863template <
typename InputIt,
typename>
864typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator
866 const_iterator pos, InputIt first, InputIt last) {
868 if constexpr (std::is_same_v<
869 typename std::iterator_traits<InputIt>::iterator_category,
870 std::input_iterator_tag>) {
873 iterator insert_pos = iterator(derived(), pos.pos_);
874 while (first != last) {
875 insert_pos = emplace(insert_pos, *first);
879 return iterator(derived(), pos.pos_);
881 std::optional<iterator> result = try_insert(pos, first, last);
882 PW_ASSERT(result.has_value());
887template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
888template <
typename ForwardIt,
typename>
890 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
892 const_iterator pos, ForwardIt first, ForwardIt last) {
893 static_assert(std::is_convertible_v<
894 typename std::iterator_traits<ForwardIt>::iterator_category,
895 std::forward_iterator_tag>);
896 const auto distance = std::distance(first, last);
897 PW_DASSERT(distance >= 0);
898 const size_type count =
static_cast<size_type
>(distance);
900 const iterator it(derived(), pos.pos_);
904 if (!ShiftForInsert(pos.pos_, count)) {
907 std::uninitialized_move(first, last, it);
911template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
912template <
typename... Args>
914 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
915GenericDeque<Derived, ValueType, CountAndCapacityType>::try_emplace_shift_right(
916 const_iterator pos, Args&&... args) {
917 if (!CheckCapacityAdd(1)) {
920 ShiftRight(pos.pos_, 1);
921 iterator it(derived(), pos.pos_);
922 new (std::addressof(*it)) value_type(std::forward<Args>(args)...);
926template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
928 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
929GenericDeque<Derived, ValueType, CountAndCapacityType>::try_insert_shift_right(
930 const_iterator pos, size_type count,
const value_type& value) {
932 return iterator(derived(), pos.pos_);
934 if (!CheckCapacityAdd(count)) {
938 ShiftRight(pos.pos_, count);
939 iterator it(derived(), pos.pos_);
940 std::uninitialized_fill_n(it, count, value);
944template <
typename Derived,
typename ValueType,
typename CountAndCapacityType>
945template <
typename ForwardIt,
typename>
947 typename GenericDeque<Derived, ValueType, CountAndCapacityType>::iterator>
948GenericDeque<Derived, ValueType, CountAndCapacityType>::try_insert_shift_right(
949 const_iterator pos, ForwardIt first, ForwardIt last) {
950 static_assert(std::is_convertible_v<
951 typename std::iterator_traits<ForwardIt>::iterator_category,
952 std::forward_iterator_tag>);
953 const auto distance = std::distance(first, last);
954 PW_DASSERT(distance >= 0);
955 const size_type count =
static_cast<size_type
>(distance);
957 const iterator it(derived(), pos.pos_);
961 if (!CheckCapacityAdd(count)) {
964 ShiftRight(pos.pos_, count);
965 std::uninitialized_move(first, last, it);
Definition: generic_deque.h:55
Definition: generic_deque.h:180
constexpr size_type size() const noexcept
Returns the number of elements in the deque.
Definition: generic_deque.h:64
constexpr size_type capacity() const noexcept
Returns the maximum number of elements in the deque.
Definition: generic_deque.h:69
Definition: span_impl.h:235
constexpr size_type size() const noexcept
Returns the number of elements in the deque.
Definition: generic_deque.h:64
iterator insert(const_iterator pos, size_type count, const value_type &value)
Definition: generic_deque.h:375
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:653
std::optional< iterator > try_insert(const_iterator pos, std::initializer_list< value_type > ilist)
Definition: generic_deque.h:505
bool try_assign(size_type count, const value_type &value)
Definition: generic_deque.h:615
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:223
iterator insert(const_iterator pos, const value_type &value)
Definition: generic_deque.h:355
void assign(It start, It finish)
Definition: generic_deque.h:597
iterator erase(const_iterator first, const_iterator last)
Definition: generic_deque.h:734
std::optional< iterator > try_emplace(const_iterator pos, Args &&... args)
bool try_assign(const std::initializer_list< value_type > &list)
Definition: generic_deque.h:445
iterator emplace(const_iterator pos, Args &&... args)
Definition: generic_deque.h:345
iterator erase(const_iterator pos)
Erases the item at pos, which must be a dereferenceable iterator.
Definition: generic_deque.h:305
iterator insert(const_iterator pos, InputIt first, InputIt last)
Definition: generic_deque.h:865
constexpr size_type capacity() const noexcept
Returns the maximum number of elements in the deque.
Definition: generic_deque.h:69
std::optional< iterator > try_insert(const_iterator pos, const value_type &value)
Definition: generic_deque.h:465
std::optional< iterator > try_insert(const_iterator pos, value_type &&value)
Definition: generic_deque.h:475
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:211
iterator insert(const_iterator pos, value_type &&value)
Definition: generic_deque.h:365
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:394
constexpr bool CheckedAdd(A a, B b, T &result)
Definition: checked_arithmetic.h:70