30 using internal_storage_value_type = std::conditional_t<std::is_same_v<type_t, bool>, std::uint8_t, type_t>;
31 using internal_storage_allocator_type =
typename std::allocator_traits<allocator_t>::template rebind_alloc<internal_storage_value_type>;
32 using internal_base_type = std::vector<internal_storage_value_type, internal_storage_allocator_type>;
34 class internal_iterator {
36 using iterator_base_type =
typename internal_base_type::iterator;
37 using iterator_category = std::random_access_iterator_tag;
43 internal_iterator() =
default;
44 explicit internal_iterator(iterator_base_type it) : it_(it) {}
47 pointer operator ->()
const {
return reinterpret_cast<pointer>(std::addressof(*it_));}
49 internal_iterator& operator ++() {++it_;
return *
this;}
50 internal_iterator operator ++(
int) {internal_iterator tmp(*
this); ++(*this);
return tmp;}
51 internal_iterator& operator --() {--it_;
return *
this;}
52 internal_iterator operator --(
int) {internal_iterator tmp(*
this); --(*this);
return tmp;}
55 internal_iterator operator +(
difference_type n)
const {
return internal_iterator(it_ +
n);}
57 internal_iterator operator -(
difference_type n)
const {
return internal_iterator(it_ -
n);}
62 bool operator ==(
const internal_iterator &
other)
const {
return it_ ==
other.it_;}
63 bool operator !=(
const internal_iterator &
other)
const {
return it_ !=
other.it_;}
64 bool operator <(
const internal_iterator &
other)
const {
return it_ <
other.it_;}
65 bool operator <=(
const internal_iterator &
other)
const {
return it_ <=
other.it_;}
66 bool operator >(
const internal_iterator &
other)
const {
return it_ >
other.it_;}
67 bool operator >=(
const internal_iterator &
other)
const {
return it_ >=
other.it_;}
69 iterator_base_type to_base_type()
const {
return it_;}
73 iterator_base_type it_;
76 class internal_const_iterator {
78 using iterator_base_type =
typename internal_base_type::const_iterator;
79 using iterator_category = std::random_access_iterator_tag;
85 internal_const_iterator() =
default;
86 explicit internal_const_iterator(iterator_base_type it) : it_(it) {}
87 internal_const_iterator(
const internal_iterator & it) : it_(it.it_) {}
90 pointer operator->()
const {
return reinterpret_cast<pointer>(std::addressof(*it_));}
92 internal_const_iterator& operator ++() {++it_;
return *
this;}
93 internal_const_iterator operator ++(
int) {internal_const_iterator tmp(*
this); ++(*this);
return tmp;}
94 internal_const_iterator& operator --() {--it_;
return *
this;}
95 internal_const_iterator operator --(
int) {internal_const_iterator tmp(*
this); --(*this);
return tmp;}
98 internal_const_iterator operator +(
difference_type n)
const {
return internal_const_iterator(it_ +
n);}
100 internal_const_iterator operator -(
difference_type n)
const {
return internal_const_iterator(it_ -
n);}
105 bool operator ==(
const internal_const_iterator &
other)
const {
return it_ ==
other.it_;}
106 bool operator !=(
const internal_const_iterator &
other)
const {
return it_ !=
other.it_;}
107 bool operator <(
const internal_const_iterator &
other)
const {
return it_ <
other.it_;}
108 bool operator <=(
const internal_const_iterator &
other)
const {
return it_ <=
other.it_;}
109 bool operator >(
const internal_const_iterator &
other)
const {
return it_ >
other.it_;}
110 bool operator >=(
const internal_const_iterator &
other)
const {
return it_ >=
other.it_;}
112 iterator_base_type to_base_type()
const {
return it_;}
116 iterator_base_type it_;
141 inline static constexpr size_type npos = std::numeric_limits<size_type>::max();
167 template<
class input_iterator_t>
175 items_.reserve(items.size());
177 items_.push_back(
b ? 1 : 0);
188 [[nodiscard]]
auto back() ->
reference {
return at(size() - 1);}
189 [[nodiscard]]
auto back() const ->
const_reference {
return at(size() - 1);}
191 [[nodiscard]]
auto begin() noexcept ->
iterator {
return to_type_iterator(items_.begin());}
192 [[nodiscard]]
auto begin() const noexcept ->
const_iterator {
return to_type_iterator(items_.cbegin());}
194 [[nodiscard]]
auto capacity() const noexcept ->
size_type {
return items_.capacity();}
196 [[nodiscard]]
auto cbegin() const noexcept ->
const_iterator {
return to_type_iterator(items_.cbegin());}
197 [[nodiscard]]
auto cend() const noexcept ->
const_iterator {
return to_type_iterator(items_.cend()); }
202 [[nodiscard]]
auto data() noexcept ->
pointer {
return reinterpret_cast<pointer>(items_.data());}
205 [[nodiscard]]
auto empty() const noexcept ->
bool {
return items_.empty();}
207 [[nodiscard]]
auto end() noexcept ->
iterator {
return to_type_iterator(items_.end());}
208 [[nodiscard]]
auto end() const noexcept ->
const_iterator {
return to_type_iterator(items_.cend());}
210 [[nodiscard]]
auto front() ->
reference {
return at(0);}
213 [[nodiscard]]
auto items() const noexcept ->
const_base_type& {
return items_;}
214 [[nodiscard]]
auto items() noexcept ->
base_type& {
return items_;}
216 [[nodiscard]]
auto max_size() const noexcept ->
size_type {
return std::min(items_.max_size(),
npos / 2);}
224 [[nodiscard]]
auto size() const noexcept ->
size_type {
return items_.size();}
226 [[nodiscard]]
auto version() const noexcept ->
size_type {
return version_;}
232 auto assign(
size_type count,
const type_t& value) ->
void {++version_; items_.assign(count, value);}
233 template<
class input_iterator_t>
234 auto assign(input_iterator_t
first, input_iterator_t
last) ->
void {++version_; items_.assign(
first,
last);}
235 auto assign(std::initializer_list<type_t> items) ->
void {++version_; items_.assign(items.begin(), items.end());}
240 auto clear() ->
void {++version_; items_.clear();}
242 template<
class ...args_t>
243 auto emplace(
const_iterator pos, args_t&&... args) ->
iterator {++version_;
return to_type_iterator(items_.emplace(pos.to_base_type(), std::forward<args_t>(args)...));}
244 template<
class ...args_t>
245 auto emplace_back(args_t&&... args) ->
reference {++version_;
return reinterpret_cast<reference>(items_.emplace_back(std::forward<args_t>(args)...));}
247 auto erase(
const_iterator pos) ->
iterator {++version_;
return to_type_iterator(items_.erase(pos.to_base_type()));}
250 auto get_allocator() const ->
allocator_type {
return items_.get_allocator();}
252 auto increment_version() noexcept ->
size_type {
return ++version_;}
254 auto insert(
const_iterator pos,
const type_t& value) ->
iterator {++version_;
return to_type_iterator(items_.insert(pos.to_base_type(), value));}
255 auto insert(
const_iterator pos, type_t&& value) ->
iterator {++version_;
return to_type_iterator(items_.insert(pos.to_base_type(), std::move(value)));}
258 template<
class input_iterator_t>
260 auto insert(
const_iterator pos,
const std::initializer_list<type_t>& items) ->
iterator {++version_;
return to_type_iterator(items_.insert(pos.to_base_type(), items.begin(), items.end()));}
262 auto pop_back() ->
void {++version_; items_.pop_back();}
263 auto push_back(
const type_t& value) ->
void {++version_; items_.push_back(value);}
264 auto push_back(type_t&& value) ->
void {++version_; items_.push_back(std::move(value));}
266 auto reserve(
size_type new_cap) ->
void {++version_; items_.reserve(new_cap);}
269 auto resize(
size_type count,
const value_type & value) ->
void {++version_; items_.resize(count, value);}
271 auto shrink_to_fit() ->
void {++version_; items_.shrink_to_fit();}
280 auto operator =(std::initializer_list<type_t>& items) ->
raw_array&
requires(!std::is_same_v<type_t, bool>) {
285 auto operator =(std::initializer_list<bool>& items) ->
raw_array&
requires(std::is_same_v<type_t, bool>) {
288 items_.reserve(items.size());
290 items_.push_back(
b ? 1 : 0);
295 return a.items() ==
b.items();
297 friend auto operator ==(
const raw_array<type_t>&
a,
const std::vector<type_t>&
b) ->
bool {
298 return a.items() ==
b;
300 friend auto operator ==(
const std::vector<type_t>&
a,
const raw_array<type_t>&
b) ->
bool {
301 return a ==
b.items();
305 return a.items() !=
b.items();
307 friend auto operator !=(
const raw_array<type_t>&
a,
const std::vector<type_t>&
b) ->
bool {
308 return a.items() !=
b;
310 friend auto operator !=(
const std::vector<type_t>&
a,
const raw_array<type_t>&
b) ->
bool {
311 return a !=
b.items();
317 operator const base_type& ()
const noexcept {
return items_;}
318 operator base_type& ()
noexcept {
return items_;}
322 auto to_type_iterator(
typename base_type::iterator it) ->
iterator {
return iterator(it); }