31 using internal_storage_value_type = std::conditional_t<std::is_same_v<type_t, bool>, std::uint8_t, type_t>;
32 using internal_storage_allocator_type =
typename std::allocator_traits<allocator_t>::template rebind_alloc<internal_storage_value_type>;
33 using internal_base_type = std::vector<internal_storage_value_type, internal_storage_allocator_type>;
35 class internal_iterator {
37 using iterator_base_type =
typename internal_base_type::iterator;
38 using iterator_category = std::random_access_iterator_tag;
44 internal_iterator() =
default;
45 explicit internal_iterator(iterator_base_type it) : it_(it) {}
48 pointer operator ->()
const {
return reinterpret_cast<pointer>(std::addressof(*it_));}
50 internal_iterator& operator ++() {++it_;
return *
this;}
51 internal_iterator operator ++(
int) {internal_iterator tmp(*
this); ++(*this);
return tmp;}
52 internal_iterator& operator --() {--it_;
return *
this;}
53 internal_iterator operator --(
int) {internal_iterator tmp(*
this); --(*this);
return tmp;}
56 internal_iterator operator +(
difference_type n)
const {
return internal_iterator(it_ +
n);}
58 internal_iterator operator -(
difference_type n)
const {
return internal_iterator(it_ -
n);}
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_;}
68 bool operator >=(
const internal_iterator &
other)
const {
return it_ >=
other.it_;}
70 iterator_base_type to_base_type()
const {
return it_;}
74 iterator_base_type it_;
77 class internal_const_iterator {
79 using iterator_base_type =
typename internal_base_type::const_iterator;
80 using iterator_category = std::random_access_iterator_tag;
86 internal_const_iterator() =
default;
87 explicit internal_const_iterator(iterator_base_type it) : it_(it) {}
88 internal_const_iterator(
const internal_iterator & it) : it_(it.it_) {}
91 pointer operator->()
const {
return reinterpret_cast<pointer>(std::addressof(*it_));}
93 internal_const_iterator& operator ++() {++it_;
return *
this;}
94 internal_const_iterator operator ++(
int) {internal_const_iterator tmp(*
this); ++(*this);
return tmp;}
95 internal_const_iterator& operator --() {--it_;
return *
this;}
96 internal_const_iterator operator --(
int) {internal_const_iterator tmp(*
this); --(*this);
return tmp;}
99 internal_const_iterator operator +(
difference_type n)
const {
return internal_const_iterator(it_ +
n);}
100 internal_const_iterator& operator -=(
difference_type n) {it_ -=
n;
return *
this;}
101 internal_const_iterator operator -(
difference_type n)
const {
return internal_const_iterator(it_ -
n);}
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_;}
111 bool operator >=(
const internal_const_iterator &
other)
const {
return it_ >=
other.it_;}
113 iterator_base_type to_base_type()
const {
return it_;}
117 iterator_base_type it_;
142 inline static constexpr size_type npos = std::numeric_limits<size_type>::max();
168 template<
typename input_iterator_t>
176 items_.reserve(items.size());
177 for (
const auto&
b : items)
178 items_.push_back(
b ? 1 : 0);
182 template<xtd::forward_iterable source_t>
191 [[nodiscard]]
auto back() ->
reference {
return at(
size() - 1);}
194 [[nodiscard]]
auto begin() noexcept ->
iterator {
return to_type_iterator(items_.begin());}
195 [[nodiscard]]
auto begin() const noexcept ->
const_iterator {
return to_type_iterator(items_.cbegin());}
197 [[nodiscard]]
auto capacity() const noexcept ->
size_type {
return items_.capacity();}
199 [[nodiscard]]
auto cbegin() const noexcept ->
const_iterator {
return to_type_iterator(items_.cbegin());}
200 [[nodiscard]]
auto cend() const noexcept ->
const_iterator {
return to_type_iterator(items_.cend()); }
205 [[nodiscard]]
auto data() noexcept ->
pointer {
return reinterpret_cast<pointer>(items_.data());}
208 [[nodiscard]]
auto empty() const noexcept ->
bool {
return items_.empty();}
210 [[nodiscard]]
auto end() noexcept ->
iterator {
return to_type_iterator(items_.end());}
211 [[nodiscard]]
auto end() const noexcept ->
const_iterator {
return to_type_iterator(items_.cend());}
213 [[nodiscard]]
auto front() ->
reference {
return at(0);}
216 [[nodiscard]]
auto items() const noexcept ->
const_base_type& {
return items_;}
217 [[nodiscard]]
auto items() noexcept ->
base_type& {
return items_;}
219 [[nodiscard]]
auto max_size() const noexcept ->
size_type {
return std::min(items_.max_size(),
npos / 2);}
227 [[nodiscard]]
auto size() const noexcept ->
size_type {
return items_.size();}
229 [[nodiscard]]
auto version() const noexcept ->
size_type {
return version_;}
235 auto assign(
size_type count,
const type_t& value) ->
void {++version_; items_.assign(count, value);}
236 template<
typename input_iterator_t>
237 auto assign(input_iterator_t
first, input_iterator_t
last) ->
void {++version_; items_.assign(
first,
last);}
238 auto assign(std::initializer_list<type_t> items) ->
void {++version_; items_.assign(items.begin(), items.end());}
243 auto clear() ->
void {++version_; items_.clear();}
245 template<
typename ...args_t>
246 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)...));}
247 template<
typename ...args_t>
248 auto emplace_back(args_t&&... args) ->
reference {++version_;
return reinterpret_cast<reference>(items_.emplace_back(std::forward<args_t>(args)...));}
250 auto erase(
const_iterator pos) ->
iterator {++version_;
return to_type_iterator(items_.erase(pos.to_base_type()));}
253 auto get_allocator() const ->
allocator_type {
return items_.get_allocator();}
255 auto increment_version() noexcept ->
size_type {
return ++version_;}
257 auto insert(
const_iterator pos,
const type_t& value) ->
iterator {++version_;
return to_type_iterator(items_.insert(pos.to_base_type(), value));}
258 auto insert(
const_iterator pos, type_t&& value) ->
iterator {++version_;
return to_type_iterator(items_.insert(pos.to_base_type(), std::move(value)));}
259 auto insert(
const_iterator pos,
size_type count,
const type_t& value) ->
iterator {++version_;
return to_type_iterator(items_.insert(pos.to_base_type(), count, value));}
260 auto insert(
const_iterator pos,
size_type count, type_t&& value) ->
iterator {++version_;
return to_type_iterator(items_.insert(pos.to_base_type(), count, std::move(value)));}
261 template<
typename input_iterator_t>
263 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()));}
265 auto pop_back() ->
void {++version_; items_.pop_back();}
266 auto push_back(
const type_t& value) ->
void {++version_; items_.push_back(value);}
267 auto push_back(type_t&& value) ->
void {++version_; items_.push_back(std::move(value));}
269 auto reserve(
size_type new_cap) ->
void {++version_; items_.reserve(new_cap);}
272 auto resize(
size_type count,
const value_type & value) ->
void {++version_; items_.resize(count, value);}
274 auto shrink_to_fit() ->
void {++version_; items_.shrink_to_fit();}
283 auto operator =(std::initializer_list<type_t>& items) ->
raw_array&
requires(!std::is_same_v<type_t, bool>) {
288 auto operator =(std::initializer_list<bool>& items) ->
raw_array&
requires(std::is_same_v<type_t, bool>) {
291 items_.reserve(items.size());
292 for (
const auto&
b : items)
293 items_.push_back(
b ? 1 : 0);
298 return a.items() ==
b.items();
300 friend auto operator ==(
const raw_array<type_t>&
a,
const std::vector<type_t>&
b) ->
bool {
301 return a.items() ==
b;
303 friend auto operator ==(
const std::vector<type_t>&
a,
const raw_array<type_t>&
b) ->
bool {
304 return a ==
b.items();
308 return a.items() !=
b.items();
310 friend auto operator !=(
const raw_array<type_t>&
a,
const std::vector<type_t>&
b) ->
bool {
311 return a.items() !=
b;
313 friend auto operator !=(
const std::vector<type_t>&
a,
const raw_array<type_t>&
b) ->
bool {
314 return a !=
b.items();
320 operator const base_type& ()
const noexcept {
return items_;}
321 operator base_type& ()
noexcept {
return items_;}
325 auto to_type_iterator(
typename base_type::iterator it) ->
iterator {
return iterator(it); }