9 #include <libcaramel/iterators/random_iterator.hpp>
10 #include <libcaramel/memory/memory_allocator.hpp>
11 #include <libcaramel/util/types.hpp>
13 #include <gsl/gsl_assert>
17 #include <initializer_list>
20 #include <type_traits>
22 namespace caramel::detail
24 template <
typename First,
typename Second>
25 auto synth_three_way(
const First& lhs,
const Second& rhs)
27 if constexpr (std::three_way_comparable_with<First, Second>)
35 return std::strong_ordering::equal;
40 return std::strong_ordering::less;
43 return std::strong_ordering::greater;
68 template <
typename Any, i64_t Size,
typename Allocator = memory_allocator<Any>>
72 using value_type = Any;
73 using size_type = std::int64_t;
74 using difference_type = std::ptrdiff_t;
75 using allocator_type = Allocator;
76 using reference = value_type&;
77 using const_reference =
const value_type&;
78 using pointer =
typename Allocator::pointer;
79 using const_pointer =
typename Allocator::const_pointer;
82 using reverse_iterator = std::reverse_iterator<iterator>;
83 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
106 const allocator_type&
allocator = allocator_type{}) :
111 assign(count, value);
120 const allocator_type&
allocator = allocator_type{}) :
132 template <std::input_iterator InputIt>
134 const allocator_type&
allocator = allocator_type{}) :
169 m_allocator.deallocate(gsl::make_not_null(mp_begin),
count_t{
capacity()});
176 const size_type new_count = std::distance(std::begin(other), std::end(other));
184 std::uninitialized_copy(std::begin(other), std::end(other),
begin());
198 *
this = std::move(other);
215 m_allocator.deallocate(gsl::make_not_null(mp_begin),
count_t{
capacity()});
222 using mi = std::move_iterator<iterator>;
223 assign(mi{other.begin()}, mi{other.end()});
225 other.reset_to_static();
234 if (!is_static() && mp_begin)
236 m_allocator.deallocate(gsl::make_not_null(mp_begin),
count_t{
capacity()});
251 if (m_allocator != rhs.m_allocator)
257 m_allocator.deallocate(gsl::make_not_null(mp_begin),
count_t{
capacity()});
263 m_allocator = rhs.m_allocator;
265 assign(rhs.begin(), rhs.end());
278 if (m_allocator != rhs.allocator())
280 using move_it = std::move_iterator<iterator>;
281 assign(move_it{rhs.begin()}, move_it{rhs.end()});
283 rhs.reset_to_static();
287 if (!rhs.is_static())
293 m_allocator.deallocate(gsl::make_not_null(mp_begin),
count_t{
capacity()});
299 m_capacity = rhs.capacity();
300 mp_begin = rhs.mp_begin;
304 using move_it = std::move_iterator<iterator>;
305 assign(move_it{rhs.begin()}, move_it{rhs.end()});
308 rhs.reset_to_static();
331 constexpr
auto allocator() const noexcept -> allocator_type {
return m_allocator; }
343 constexpr
auto lookup(size_type index) -> reference
345 Expects(index < m_size);
348 return mp_begin[index];
360 constexpr
auto lookup(size_type index)
const -> const_reference
362 Expects(index < m_size);
364 return mp_begin[index];
373 constexpr
auto data() noexcept -> pointer {
return pointer{&(*
begin())}; }
380 constexpr
auto data() const noexcept -> const_pointer {
return const_pointer{&(*
cbegin())}; }
442 constexpr
auto rbegin() noexcept -> reverse_iterator {
return reverse_iterator{
end()}; }
450 constexpr
auto rbegin() const noexcept -> const_reverse_iterator
452 return const_reverse_iterator{
cend()};
462 constexpr
auto rcbegin() const noexcept -> const_reverse_iterator
464 return const_reverse_iterator{
cend()};
475 constexpr
auto rend() noexcept -> reverse_iterator {
return reverse_iterator{
begin()}; }
484 constexpr
auto rend() const noexcept -> const_reverse_iterator
486 return const_reverse_iterator{
cbegin()};
496 constexpr
auto rcend() const noexcept -> const_reverse_iterator
498 return const_reverse_iterator{
cbegin()};
506 [[nodiscard]] constexpr
auto empty() const noexcept ->
bool {
return begin() ==
end(); };
512 [[nodiscard]] constexpr
auto size() const noexcept -> size_type {
return m_size; };
519 [[nodiscard]] constexpr
auto capacity() const noexcept -> size_type {
return m_capacity; };
561 Expects(pos <=
cend());
573 size_type offset = pos -
cbegin();
575 new_pos =
begin() + offset;
582 std::construct_at(offset(
size()), std::move(*(
end() - 1)));
583 std::move_backward(new_pos,
end() - 1,
end());
587 const_pointer p_element = &value;
588 if (pointer{&(*new_pos)} <= p_element && pointer{&(*
end())} > p_element)
593 *new_pos = *p_element;
613 Expects(pos <=
cend());
625 size_type offset = pos -
cbegin();
627 new_pos =
begin() + offset;
634 construct(offset(
size()), std::move(*(
end() - 1)));
636 std::move_backward(new_pos,
end() - 1,
end());
640 pointer p_element = &value;
641 if (pointer{&(*new_pos)} <= p_element && pointer{&(*
end())} > p_element)
646 *new_pos = std::move(*p_element);
662 template <
typename... Args>
666 Expects(pos <=
cend());
670 append(in_place, std::forward<Args>(args)...);
678 size_type offset = pos -
cbegin();
680 new_pos =
begin() + offset;
687 new (&(*
end())) value_type(std::move(*(
end() - 1)));
689 std::move_backward(new_pos,
end() - 1,
end());
693 *new_pos = value_type(std::forward<Args>(args)...);
713 Expects(pos <=
cend());
715 size_type start_index = pos -
cbegin();
721 grow(
size() + count);
724 std::uninitialized_fill_n(
end(), count, value);
728 return begin() + start_index;
737 std::uninitialized_move(
end() - count,
end(),
end());
741 std::move_backward(updated_pos, old_end - count, old_end);
742 std::fill_n(updated_pos, count, value);
746 size_type move_count = old_end - updated_pos;
749 std::uninitialized_move(updated_pos, old_end,
end() - move_count);
750 std::fill_n(updated_pos, move_count, value);
751 std::uninitialized_fill_n(old_end, count - move_count, value);
770 template <std::input_iterator InputIt>
774 Expects(pos <=
cend());
776 size_type start_index = pos -
cbegin();
777 difference_type count = std::distance(first, last);
783 grow(
size() + count);
786 std::uninitialized_copy(first, last,
end());
790 return begin() + start_index;
798 std::uninitialized_move(
end() - count,
end(),
end());
802 std::move_backward(updated_pos, old_end - count, old_end);
803 std::copy(first, last, updated_pos);
807 size_type move_count = old_end - updated_pos;
810 std::uninitialized_move(updated_pos, old_end,
end() - move_count);
812 for (
auto it = updated_pos; count > 0; --count)
820 std::uninitialized_copy(first, last, old_end);
841 return insert(pos, init_list.begin(), init_list.end());
855 Expects(pos <=
cend());
864 std::move(it + 1,
end(), it);
886 Expects(first >=
cbegin());
887 Expects(last <=
cend());
888 Expects(first >= last);
895 size_type
const distance = std::distance(first, last);
901 std::destroy(it,
end());
914 constexpr
void append(
const value_type& value)
921 construct(mp_begin +
size(), value);
931 constexpr
void append(value_type&& value)
938 construct(mp_begin +
size(), std::move(value));
948 template <
typename... Args>
958 std::construct_at(offset(
size()), std::forward<Args>(args)...);
972 Expects(
size() != 0);
974 std::destroy_at(offset(
size()));
989 std::destroy(
begin() + count,
end());
992 else if (
size() < count)
999 for (size_type i =
size(); i < count; ++i)
1001 construct(offset(i), value_type{});
1015 constexpr
void resize(size_type count, const_reference value)
1019 std::destroy(
begin() + count,
end());
1022 else if (
size() < count)
1029 std::uninitialized_fill(
end(),
begin() + count, value);
1036 [[nodiscard]] constexpr
auto is_static() const noexcept ->
bool
1038 return mp_begin == get_first_element();
1041 constexpr
auto get_first_element() const -> pointer
1043 return const_cast<pointer
>(
reinterpret_cast<const_pointer
>(&m_static_storage));
1046 constexpr
void grow(size_type min_size = 0)
1048 const auto new_capacity = compute_new_capacity(std::max(m_capacity + 1, min_size));
1049 auto* new_elements = m_allocator.allocate(count_t{new_capacity});
1051 if constexpr (std::is_move_constructible_v<value_type>)
1053 std::uninitialized_move(
begin(),
end(), iterator{new_elements});
1057 std::uninitialized_copy(
begin(),
end(), iterator{new_elements});
1066 m_allocator.deallocate(gsl::make_not_null(mp_begin), count_t{
capacity()});
1070 mp_begin = new_elements;
1071 m_capacity = new_capacity;
1074 constexpr
void reset_to_static()
1076 mp_begin = get_first_element();
1081 constexpr
void assign(size_type count, const_reference value)
1085 if (count > m_capacity)
1092 std::uninitialized_fill(
begin(),
end(), value);
1095 template <std::input_iterator InputIt>
1096 constexpr
void assign(InputIt first, InputIt last)
1100 const auto new_count =
static_cast<size_type
>(std::distance(first, last));
1108 std::uninitialized_copy(first, last,
begin());
1111 constexpr
void assign(std::initializer_list<value_type> initializer_list)
1113 assign(initializer_list.begin(), initializer_list.end());
1116 constexpr
auto offset(size_type i) noexcept -> pointer {
return mp_begin + i; }
1117 constexpr
auto offset(size_type i)
const noexcept -> const_pointer {
return mp_begin + i; }
1119 static constexpr
auto compute_new_capacity(size_type min_capacity) -> size_type
1121 constexpr
auto max_digits = std::numeric_limits<size_type>::digits;
1122 constexpr
auto max_capacity = size_type{1} << (max_digits - 1);
1124 if (min_capacity > max_capacity)
1126 return max_capacity;
1131 for (size_type i = 1; i < max_digits; i *= 2)
1133 min_capacity |= min_capacity >> i;
1136 return ++min_capacity;
1140 pointer mp_begin{
nullptr};
1142 alignas(
alignof(Any)) std::array<std::byte,
sizeof(Any) * Size> m_static_storage;
1144 size_type m_size{0u};
1145 size_type m_capacity{0u};
1147 allocator_type m_allocator;
1150 template <std::equality_comparable Any, i64_t SizeOne, i64_t SizeTwo,
typename allocator>
1151 constexpr
auto operator==(
const basic_dynamic_array<Any, SizeOne, allocator>& lhs,
1152 const basic_dynamic_array<Any, SizeTwo, allocator>& rhs) ->
bool
1154 return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs), std::end(rhs));
1157 template <
typename Any, i64_t SizeOne, i64_t SizeTwo,
typename allocator>
1158 constexpr
auto operator<=>(
const basic_dynamic_array<Any, SizeOne, allocator>& lhs,
1159 const basic_dynamic_array<Any, SizeTwo, allocator>& rhs)
1161 return std::lexicographical_compare_three_way(std::begin(lhs), std::end(lhs), std::begin(rhs),
1162 std::end(rhs), detail::synth_three_way);
1165 template <
typename Iter, i64_t Size = 0,
1166 typename Allocator = memory_allocator<typename std::iterator_traits<Iter>::value_type>>
1167 basic_dynamic_array(Iter, Iter)
1168 -> basic_dynamic_array<typename std::iterator_traits<Iter>::value_type, Size, Allocator>;
1170 template <
typename Any,
typename... U,
typename Allocator = memory_allocator<Any>>
1171 basic_dynamic_array(Any, U...) -> basic_dynamic_array<Any, 1 +
sizeof...(U), Allocator>;
1182 template <
typename Any, i64_t Size>
1188 using value_type = Any;
1189 using size_type =
typename underlying_type::size_type;
1190 using difference_type = std::ptrdiff_t;
1192 using reference = value_type&;
1193 using const_reference =
const value_type&;
1194 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
1195 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
1198 using reverse_iterator = std::reverse_iterator<iterator>;
1199 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1213 m_underlying{count, value}
1227 template <std::input_iterator InputIt>
1238 m_underlying = init_list;
1263 constexpr
auto lookup(size_type index) -> reference {
return m_underlying.
lookup(index); }
1274 constexpr
auto lookup(size_type index)
const -> const_reference
1276 return m_underlying.
lookup(index);
1285 constexpr
auto data() noexcept -> pointer {
return m_underlying.
data(); }
1292 constexpr
auto data() const noexcept -> const_pointer {
return m_underlying.
data(); }
1300 constexpr
auto begin() noexcept -> iterator {
return m_underlying.
begin(); }
1307 constexpr
auto begin() const noexcept -> const_iterator {
return m_underlying.
begin(); }
1314 constexpr
auto cbegin() const noexcept -> const_iterator {
return m_underlying.
cbegin(); }
1323 constexpr
auto end() noexcept -> iterator {
return m_underlying.
end(); }
1331 constexpr
auto end() const noexcept -> const_iterator {
return m_underlying.
end(); }
1339 constexpr
auto cend() const noexcept -> const_iterator {
return m_underlying.
cend(); }
1348 constexpr
auto rbegin() noexcept -> reverse_iterator {
return m_underlying.
rbegin(); }
1356 constexpr
auto rbegin() const noexcept -> const_reverse_iterator
1358 return m_underlying.
rbegin();
1368 constexpr
auto rcbegin() const noexcept -> const_reverse_iterator
1370 return m_underlying.
rcbegin();
1381 constexpr
auto rend() noexcept -> reverse_iterator {
return m_underlying.
end(); }
1390 constexpr
auto rend() const noexcept -> const_reverse_iterator {
return m_underlying.
rend(); }
1399 constexpr
auto rcend() const noexcept -> const_reverse_iterator
1401 return m_underlying.
rcend();
1409 [[nodiscard]] constexpr
auto empty() const noexcept ->
bool {
return m_underlying.
empty(); };
1415 [[nodiscard]] constexpr
auto size() const noexcept -> size_type
1417 return m_underlying.
size();
1425 [[nodiscard]] constexpr
auto capacity() const noexcept -> size_type
1457 constexpr
auto insert(const_iterator pos, const_reference value) -> iterator
1459 return m_underlying.
insert(pos, value);
1474 constexpr
auto insert(const_iterator pos, value_type&& value) -> iterator
1476 return m_underlying.
insert(pos, std::move(value));
1490 template <
typename... Args>
1491 constexpr
auto insert(const_iterator pos, Args... args) -> iterator
1493 return m_underlying.
insert(pos, std::forward<Args>(args)...);
1508 constexpr
auto insert(const_iterator pos, size_type count, const_reference value) -> iterator
1510 return m_underlying.
insert(pos, count, value);
1526 template <std::input_iterator InputIt>
1527 constexpr
auto insert(const_iterator pos, InputIt first, InputIt last) -> iterator
1529 return m_underlying.
insert(pos, first, last);
1544 constexpr
auto insert(const_iterator pos, std::initializer_list<value_type> init_list)
1547 return m_underlying(pos, init_list);
1558 constexpr
auto erase(const_iterator pos) -> iterator {
return m_underlying.
erase(pos); }
1573 constexpr
auto erase(const_iterator first, const_iterator last) -> iterator
1575 return m_underlying.
erase(first, last);
1584 constexpr
void append(
const value_type& value) { m_underlying.
append(value); }
1591 constexpr
void append(value_type&& value) { m_underlying.
append(std::move(value)); }
1598 template <
typename... Args>
1603 return m_underlying.
append(in_place, std::forward<Args>(args)...);
1629 constexpr
void resize(size_type count, const_reference value)
1631 m_underlying.
resize(count, value);
1635 underlying_type m_underlying;
1638 template <std::equality_comparable Any, i64_t SizeOne, i64_t SizeTwo>
1639 constexpr
auto operator==(
const small_dynamic_array<Any, SizeOne>& lhs,
1640 const small_dynamic_array<Any, SizeTwo>& rhs) ->
bool
1642 return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs), std::end(rhs));
1645 template <
typename Any, i64_t SizeOne, i64_t SizeTwo>
1646 constexpr
auto operator<=>(
const small_dynamic_array<Any, SizeOne>& lhs,
1647 const small_dynamic_array<Any, SizeTwo>& rhs)
1649 return std::lexicographical_compare_three_way(std::begin(lhs), std::end(lhs), std::begin(rhs),
1650 std::end(rhs), detail::synth_three_way);
1653 template <
typename Iter, i64_t Size = 0>
1654 small_dynamic_array(Iter, Iter)
1655 -> small_dynamic_array<typename std::iterator_traits<Iter>::value_type, Size>;
1657 template <
typename Any,
typename... U>
1658 small_dynamic_array(Any, U...) -> small_dynamic_array<Any, 1 +
sizeof...(U)>;
1668 template <
typename Any>
1674 using value_type = Any;
1675 using size_type =
typename underlying_type::size_type;
1676 using difference_type = std::ptrdiff_t;
1678 using reference = value_type&;
1679 using const_reference =
const value_type&;
1680 using pointer =
typename allocator_type::pointer;
1681 using const_pointer =
typename allocator_type::const_pointer;
1684 using reverse_iterator = std::reverse_iterator<iterator>;
1685 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1698 constexpr
dynamic_array(size_type count, const_reference value) : m_underlying{count, value}
1705 constexpr
dynamic_array(std::initializer_list<Any> init) : m_underlying{init} {}
1712 template <std::input_iterator InputIt>
1713 constexpr
dynamic_array(InputIt first, InputIt last) : m_underlying{first, last}
1723 m_underlying = init_list;
1748 constexpr
auto lookup(size_type index) -> reference {
return m_underlying.
lookup(index); }
1759 constexpr
auto lookup(size_type index)
const -> const_reference
1761 return m_underlying.
lookup(index);
1770 constexpr
auto data() noexcept -> pointer {
return m_underlying.
data(); }
1777 constexpr
auto data() const noexcept -> const_pointer {
return m_underlying.
data(); }
1785 constexpr
auto begin() noexcept -> iterator {
return m_underlying.
begin(); }
1792 constexpr
auto begin() const noexcept -> const_iterator {
return m_underlying.
begin(); }
1799 constexpr
auto cbegin() const noexcept -> const_iterator {
return m_underlying.
cbegin(); }
1808 constexpr
auto end() noexcept -> iterator {
return m_underlying.
end(); }
1816 constexpr
auto end() const noexcept -> const_iterator {
return m_underlying.
end(); }
1824 constexpr
auto cend() const noexcept -> const_iterator {
return m_underlying.
cend(); }
1833 constexpr
auto rbegin() noexcept -> reverse_iterator {
return m_underlying.
rbegin(); }
1841 constexpr
auto rbegin() const noexcept -> const_reverse_iterator
1843 return m_underlying.
rbegin();
1853 constexpr
auto rcbegin() const noexcept -> const_reverse_iterator
1855 return m_underlying.
rcbegin();
1866 constexpr
auto rend() noexcept -> reverse_iterator {
return m_underlying.
end(); }
1875 constexpr
auto rend() const noexcept -> const_reverse_iterator {
return m_underlying.
rend(); }
1884 constexpr
auto rcend() const noexcept -> const_reverse_iterator
1886 return m_underlying.
rcend();
1894 [[nodiscard]] constexpr
auto empty() const noexcept ->
bool {
return m_underlying.
empty(); };
1900 [[nodiscard]] constexpr
auto size() const noexcept -> size_type
1902 return m_underlying.
size();
1910 [[nodiscard]] constexpr
auto capacity() const noexcept -> size_type
1942 constexpr
auto insert(const_iterator pos, const_reference value) -> iterator
1944 return m_underlying.
insert(pos, value);
1959 constexpr
auto insert(const_iterator pos, value_type&& value) -> iterator
1961 return m_underlying.
insert(pos, std::move(value));
1975 template <
typename... Args>
1976 constexpr
auto insert(const_iterator pos, Args... args) -> iterator
1978 return m_underlying.
insert(pos, std::forward<Args>(args)...);
1993 constexpr
auto insert(const_iterator pos, size_type count, const_reference value) -> iterator
1995 return m_underlying.
insert(pos, count, value);
2011 template <std::input_iterator InputIt>
2012 constexpr
auto insert(const_iterator pos, InputIt first, InputIt last) -> iterator
2014 return m_underlying.
insert(pos, first, last);
2029 constexpr
auto insert(const_iterator pos, std::initializer_list<value_type> init_list)
2032 return m_underlying(pos, init_list);
2043 constexpr
auto erase(const_iterator pos) -> iterator {
return m_underlying.
erase(pos); }
2058 constexpr
auto erase(const_iterator first, const_iterator last) -> iterator
2060 return m_underlying.
erase(first, last);
2069 constexpr
void append(
const value_type& value) { m_underlying.
append(value); }
2076 constexpr
void append(value_type&& value) { m_underlying.
append(std::move(value)); }
2083 template <
typename... Args>
2088 return m_underlying.
append(in_place, std::forward<Args>(args)...);
2114 constexpr
void resize(size_type count, const_reference value)
2116 m_underlying.
resize(count, value);
2120 underlying_type m_underlying;
2123 template <std::equality_comparable Any>
2124 constexpr
auto operator==(
const dynamic_array<Any>& lhs,
const dynamic_array<Any>& rhs) ->
bool
2126 return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs), std::end(rhs));
2129 template <
typename Any>
2130 constexpr
auto operator<=>(
const dynamic_array<Any>& lhs,
const dynamic_array<Any>& rhs)
2132 return std::lexicographical_compare_three_way(std::begin(lhs), std::end(lhs), std::begin(rhs),
2133 std::end(rhs), detail::synth_three_way);
2136 template <
typename Iter>
2137 dynamic_array(Iter, Iter) -> dynamic_array<typename std::iterator_traits<Iter>::value_type>;
A resizable array with a small statically allocated storage buffer.
Definition: dynamic_array.hpp:70
constexpr basic_dynamic_array(const basic_dynamic_array &other)
Construct the container using the contents of other.
Definition: dynamic_array.hpp:145
constexpr basic_dynamic_array(size_type count, const_reference value, const allocator_type &allocator=allocator_type{})
Construct the container with count copies of elements with value value.
Definition: dynamic_array.hpp:105
constexpr void reserve(size_type new_cap)
Increase the capacity of the vector to a value that's greater or equal to new_cap....
Definition: dynamic_array.hpp:529
constexpr auto insert(const_iterator pos, const_reference value) -> iterator
Inserts an element value at the position before pos in the container.
Definition: dynamic_array.hpp:558
constexpr auto data() const noexcept -> const_pointer
Access the data stored by the container.
Definition: dynamic_array.hpp:380
constexpr auto rbegin() noexcept -> reverse_iterator
Returns a reverse iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:442
constexpr auto cend() const noexcept -> const_iterator
Returns an it iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:430
constexpr auto erase(const_iterator pos) -> iterator
Erases the specified element from the container.
Definition: dynamic_array.hpp:852
constexpr void append(value_type &&value)
Appends the given element value to the end of the container. Value is moved into the new element.
Definition: dynamic_array.hpp:931
constexpr auto data() noexcept -> pointer
Access the data stored by the container.
Definition: dynamic_array.hpp:373
constexpr auto rend() noexcept -> reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:475
constexpr basic_dynamic_array(const basic_dynamic_array &other, const allocator_type &allocator)
Construct the container using the contents of other. using allocator as the allocator.
Definition: dynamic_array.hpp:160
constexpr auto cbegin() const noexcept -> const_iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:402
constexpr auto end() noexcept -> iterator
Get an iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:411
constexpr auto capacity() const noexcept -> size_type
Check the number of elements that the basic_dynamic_array has currently allocated space for.
Definition: dynamic_array.hpp:519
constexpr auto insert(const_iterator pos, InputIt first, InputIt last) -> iterator
Inserts elements from a range [first, last) before pos.
Definition: dynamic_array.hpp:771
constexpr auto end() const noexcept -> const_iterator
Return an iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:419
constexpr void pop_back()
Removes the last element in the container.
Definition: dynamic_array.hpp:970
constexpr basic_dynamic_array(std::initializer_list< Any > init, const allocator_type &allocator=allocator_type{})
Construct the container with the contents of the initializer list init.
Definition: dynamic_array.hpp:119
constexpr auto insert(const_iterator pos, size_type count, const_reference value) -> iterator
Inserts count elements from a specified value.
Definition: dynamic_array.hpp:710
constexpr basic_dynamic_array(basic_dynamic_array &&other, const allocator_type &alloc)
Construct the container with the contents of the other using move semantic. Using alloc as the alloca...
Definition: dynamic_array.hpp:209
constexpr auto insert(const_iterator pos, Args... args) -> iterator
Insert a new element into the container directly before pos. The element is constructed in-place usin...
Definition: dynamic_array.hpp:663
constexpr basic_dynamic_array() noexcept=default
Default constructor.
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Returns a reverse_iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:450
constexpr auto empty() const noexcept -> bool
Check if the basic_dynamic_array is empty.
Definition: dynamic_array.hpp:506
constexpr auto insert(const_iterator pos, std::initializer_list< value_type > init_list) -> iterator
Insert elements from an initializer_list before the position pos.
Definition: dynamic_array.hpp:838
constexpr auto insert(const_iterator pos, value_type &&value) -> iterator
Inserts an element value at the position before pos in the container.
Definition: dynamic_array.hpp:610
constexpr void resize(size_type count, const_reference value)
Resizes the container to contain count elements. If the current size is greater than count,...
Definition: dynamic_array.hpp:1015
constexpr auto operator=(basic_dynamic_array &&rhs) noexcept -> basic_dynamic_array &
Replaces the contents with those of other using move semantics.
Definition: dynamic_array.hpp:276
constexpr auto begin() const noexcept -> const_iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:395
constexpr auto lookup(size_type index) const -> const_reference
Access the object stored at a specific index.
Definition: dynamic_array.hpp:360
constexpr auto begin() noexcept -> iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:388
constexpr auto erase(const_iterator first, const_iterator last) -> iterator
Erases the specified elements from the container.
Definition: dynamic_array.hpp:884
constexpr auto allocator() const noexcept -> allocator_type
Returns the allocator associated with the container.
Definition: dynamic_array.hpp:331
constexpr basic_dynamic_array(basic_dynamic_array &&other) noexcept
Construct the container with the contents of the other using move semantic. After move,...
Definition: dynamic_array.hpp:194
constexpr auto rcbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:462
constexpr auto rend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:484
constexpr auto size() const noexcept -> size_type
Check the number of elements stored in the basic_dynamic_array.
Definition: dynamic_array.hpp:512
constexpr basic_dynamic_array(InputIt first, InputIt last, const allocator_type &allocator=allocator_type{})
Construct the container with the contents of the range [first, last)
Definition: dynamic_array.hpp:133
constexpr void append(const value_type &value)
Appends the given element value to the end of the container. The new element is initialized as a copy...
Definition: dynamic_array.hpp:914
constexpr void clear() noexcept
Erases all elements from the container, After this call, size() returs zero.
Definition: dynamic_array.hpp:540
constexpr ~basic_dynamic_array() noexcept
Destructor.
Definition: dynamic_array.hpp:230
constexpr auto operator=(std::initializer_list< Any > init_list) -> basic_dynamic_array &
Replaces the contents with those identified by initializer list init_list.
Definition: dynamic_array.hpp:319
constexpr auto operator=(const basic_dynamic_array &rhs) -> basic_dynamic_array &
Replaces the contents with an copy of the contents of rhs.
Definition: dynamic_array.hpp:247
constexpr auto rcend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:496
requires constexpr std::constructible_from< value_type, Args... > auto append(in_place_t, Args &&... args) -> reference
Appends the given element value to the end of the container. The element is constructed in-place usin...
Definition: dynamic_array.hpp:949
constexpr auto lookup(size_type index) -> reference
Access the object stored at a specific index.
Definition: dynamic_array.hpp:343
constexpr void resize(size_type count)
Resizes the container to contain count elements. If the current size is greater than count,...
Definition: dynamic_array.hpp:985
A resizable array.
Definition: dynamic_array.hpp:1670
constexpr auto cend() const noexcept -> const_iterator
Returns an it iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1824
constexpr auto size() const noexcept -> size_type
Check the number of elements stored in the basic_dynamic_array.
Definition: dynamic_array.hpp:1900
constexpr auto begin() noexcept -> iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1785
constexpr auto empty() const noexcept -> bool
Check if the basic_dynamic_array is empty.
Definition: dynamic_array.hpp:1894
constexpr void reserve(size_type new_cap)
Increase the capacity of the vector to a value that's greater or equal to new_cap....
Definition: dynamic_array.hpp:1923
constexpr auto operator=(std::initializer_list< Any > init_list) -> dynamic_array &
Replaces the contents with those identified by initializer list init_list.
Definition: dynamic_array.hpp:1721
constexpr auto rcend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:1884
constexpr dynamic_array() noexcept(noexcept(underlying_type{}))=default
Default constructor.
constexpr auto allocator() const noexcept -> allocator_type
Returns the allocator associated with the container.
Definition: dynamic_array.hpp:1733
constexpr auto rcbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:1853
constexpr void resize(size_type count)
Resizes the container to contain count elements. If the current size is greater than count,...
Definition: dynamic_array.hpp:2105
constexpr auto insert(const_iterator pos, std::initializer_list< value_type > init_list) -> iterator
Insert elements from an initializer_list before the position pos.
Definition: dynamic_array.hpp:2029
constexpr dynamic_array(size_type count, const_reference value)
Construct the container with count copies of elements with value value.
Definition: dynamic_array.hpp:1698
constexpr void resize(size_type count, const_reference value)
Resizes the container to contain count elements. If the current size is greater than count,...
Definition: dynamic_array.hpp:2114
constexpr auto insert(const_iterator pos, size_type count, const_reference value) -> iterator
Inserts count elements from a specified value.
Definition: dynamic_array.hpp:1993
constexpr auto insert(const_iterator pos, InputIt first, InputIt last) -> iterator
Inserts elements from a range [first, last) before pos.
Definition: dynamic_array.hpp:2012
constexpr dynamic_array(std::initializer_list< Any > init)
Construct the container with the contents of the initializer list init.
Definition: dynamic_array.hpp:1705
constexpr auto rend() noexcept -> reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:1866
constexpr auto erase(const_iterator first, const_iterator last) -> iterator
Erases the specified elements from the container.
Definition: dynamic_array.hpp:2058
constexpr auto end() noexcept -> iterator
Get an iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1808
constexpr void append(value_type &&value)
Appends the given element value to the end of the container. Value is moved into the new element.
Definition: dynamic_array.hpp:2076
constexpr void pop_back()
Removes the last element in the container.
Definition: dynamic_array.hpp:2096
constexpr auto insert(const_iterator pos, Args... args) -> iterator
Insert a new element into the container directly before pos. The element is constructed in-place usin...
Definition: dynamic_array.hpp:1976
constexpr auto lookup(size_type index) const -> const_reference
Access the object stored at a specific index.
Definition: dynamic_array.hpp:1759
constexpr auto data() const noexcept -> const_pointer
Access the data stored by the container.
Definition: dynamic_array.hpp:1777
requires constexpr std::constructible_from< value_type, Args... > auto append(in_place_t, Args &&... args) -> reference
Appends the given element value to the end of the container. The element is constructed in-place usin...
Definition: dynamic_array.hpp:2084
constexpr auto capacity() const noexcept -> size_type
Check the number of elements that the basic_dynamic_array has currently allocated space for.
Definition: dynamic_array.hpp:1910
constexpr void append(const value_type &value)
Appends the given element value to the end of the container. The new element is initialized as a copy...
Definition: dynamic_array.hpp:2069
constexpr auto end() const noexcept -> const_iterator
Return an iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1816
constexpr dynamic_array(InputIt first, InputIt last)
Construct the container with the contents of the range [first, last)
Definition: dynamic_array.hpp:1713
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Returns a reverse_iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:1841
constexpr auto begin() const noexcept -> const_iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1792
constexpr auto insert(const_iterator pos, value_type &&value) -> iterator
Inserts an element value at the position before pos in the container.
Definition: dynamic_array.hpp:1959
constexpr void clear() noexcept
Erases all elements from the container, After this call, size() returs zero.
Definition: dynamic_array.hpp:1928
constexpr auto lookup(size_type index) -> reference
Access the object stored at a specific index.
Definition: dynamic_array.hpp:1748
constexpr auto erase(const_iterator pos) -> iterator
Erases the specified element from the container.
Definition: dynamic_array.hpp:2043
constexpr auto rend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:1875
constexpr auto insert(const_iterator pos, const_reference value) -> iterator
Inserts an element value at the position before pos in the container.
Definition: dynamic_array.hpp:1942
constexpr auto cbegin() const noexcept -> const_iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1799
constexpr auto data() noexcept -> pointer
Access the data stored by the container.
Definition: dynamic_array.hpp:1770
constexpr auto rbegin() noexcept -> reverse_iterator
Returns a reverse iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:1833
Definition: memory_allocator.hpp:15
Definition: random_iterator.hpp:11
A resizable array with a small statically allocated storage buffer.
Definition: dynamic_array.hpp:1184
constexpr auto rcend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:1399
constexpr auto cend() const noexcept -> const_iterator
Returns an it iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1339
constexpr auto data() const noexcept -> const_pointer
Access the data stored by the container.
Definition: dynamic_array.hpp:1292
constexpr auto erase(const_iterator pos) -> iterator
Erases the specified element from the container.
Definition: dynamic_array.hpp:1558
constexpr auto insert(const_iterator pos, InputIt first, InputIt last) -> iterator
Inserts elements from a range [first, last) before pos.
Definition: dynamic_array.hpp:1527
constexpr auto erase(const_iterator first, const_iterator last) -> iterator
Erases the specified elements from the container.
Definition: dynamic_array.hpp:1573
constexpr auto lookup(size_type index) const -> const_reference
Access the object stored at a specific index.
Definition: dynamic_array.hpp:1274
constexpr auto insert(const_iterator pos, const_reference value) -> iterator
Inserts an element value at the position before pos in the container.
Definition: dynamic_array.hpp:1457
constexpr void resize(size_type count, const_reference value)
Resizes the container to contain count elements. If the current size is greater than count,...
Definition: dynamic_array.hpp:1629
constexpr small_dynamic_array(size_type count, const_reference value)
Construct the container with count copies of elements with value value.
Definition: dynamic_array.hpp:1212
requires constexpr std::constructible_from< value_type, Args... > auto append(in_place_t, Args &&... args) -> reference
Appends the given element value to the end of the container. The element is constructed in-place usin...
Definition: dynamic_array.hpp:1599
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Returns a reverse_iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:1356
constexpr void resize(size_type count)
Resizes the container to contain count elements. If the current size is greater than count,...
Definition: dynamic_array.hpp:1620
constexpr auto lookup(size_type index) -> reference
Access the object stored at a specific index.
Definition: dynamic_array.hpp:1263
constexpr small_dynamic_array(InputIt first, InputIt last)
Construct the container with the contents of the range [first, last)
Definition: dynamic_array.hpp:1228
constexpr auto rbegin() noexcept -> reverse_iterator
Returns a reverse iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:1348
constexpr auto insert(const_iterator pos, Args... args) -> iterator
Insert a new element into the container directly before pos. The element is constructed in-place usin...
Definition: dynamic_array.hpp:1491
constexpr auto rcbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first element of the reversed basic_dynamic_array....
Definition: dynamic_array.hpp:1368
constexpr auto size() const noexcept -> size_type
Check the number of elements stored in the basic_dynamic_array.
Definition: dynamic_array.hpp:1415
constexpr auto allocator() const noexcept -> allocator_type
Returns the allocator associated with the container.
Definition: dynamic_array.hpp:1248
constexpr void clear() noexcept
Erases all elements from the container, After this call, size() returs zero.
Definition: dynamic_array.hpp:1443
constexpr auto data() noexcept -> pointer
Access the data stored by the container.
Definition: dynamic_array.hpp:1285
constexpr auto rend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:1390
constexpr auto begin() noexcept -> iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1300
constexpr small_dynamic_array(std::initializer_list< Any > init)
Construct the container with the contents of the initializer list init.
Definition: dynamic_array.hpp:1220
constexpr auto capacity() const noexcept -> size_type
Check the number of elements that the basic_dynamic_array has currently allocated space for.
Definition: dynamic_array.hpp:1425
constexpr auto insert(const_iterator pos, std::initializer_list< value_type > init_list) -> iterator
Insert elements from an initializer_list before the position pos.
Definition: dynamic_array.hpp:1544
constexpr void append(value_type &&value)
Appends the given element value to the end of the container. Value is moved into the new element.
Definition: dynamic_array.hpp:1591
constexpr auto cbegin() const noexcept -> const_iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1314
constexpr auto rend() noexcept -> reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed basic_dynamic_ar...
Definition: dynamic_array.hpp:1381
constexpr auto insert(const_iterator pos, size_type count, const_reference value) -> iterator
Inserts count elements from a specified value.
Definition: dynamic_array.hpp:1508
constexpr void reserve(size_type new_cap)
Increase the capacity of the vector to a value that's greater or equal to new_cap....
Definition: dynamic_array.hpp:1438
constexpr small_dynamic_array() noexcept(noexcept(underlying_type{}))=default
Default constructor.
constexpr auto end() const noexcept -> const_iterator
Return an iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1331
constexpr void pop_back()
Removes the last element in the container.
Definition: dynamic_array.hpp:1611
constexpr void append(const value_type &value)
Appends the given element value to the end of the container. The new element is initialized as a copy...
Definition: dynamic_array.hpp:1584
constexpr auto end() noexcept -> iterator
Get an iterator to the element following the last element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1323
constexpr auto operator=(std::initializer_list< Any > init_list) -> small_dynamic_array &
Replaces the contents with those identified by initializer list init_list.
Definition: dynamic_array.hpp:1236
constexpr auto begin() const noexcept -> const_iterator
Returns an iterator to the first element of the basic_dynamic_array.
Definition: dynamic_array.hpp:1307
constexpr auto insert(const_iterator pos, value_type &&value) -> iterator
Inserts an element value at the position before pos in the container.
Definition: dynamic_array.hpp:1474
constexpr auto empty() const noexcept -> bool
Check if the basic_dynamic_array is empty.
Definition: dynamic_array.hpp:1409
Definition: strong_type.hpp:12
Definition: dynamic_array.hpp:51