28 template<
class type_t,
class allocator_t = std::allocator<type_t>>
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);
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());}
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);}
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); }
332 template<
class type_t>
335 template<
class type_t>
338 template<
class type_t,
class allocator_t = std::allocator<type_t>>
341 template<
class type_t>
344 template<
class type_t,
class allocator_t = std::allocator<type_t>>
Internal vector-like container used as a storage backend for xtd collections.
Definition raw_array.hpp:29
const value_type & const_reference
Const reference to element.
Definition raw_array.hpp:129
raw_array(size_type count, const allocator_type &alloc=allocator_type())
Create a new raw_array instance with specified count, and allocator.
Definition raw_array.hpp:162
size_t size_type
Type used for sizes.
Definition raw_array.hpp:126
internal_const_iterator const_iterator
Const forward iterator for raw_array.
Definition raw_array.hpp:133
std::ptrdiff_t difference_type
Type used for differences between iterators.
Definition raw_array.hpp:127
static constexpr size_type npos
Represents an invalid index.
Definition raw_array.hpp:141
raw_array(size_type count, const type_t &value, const allocator_type &alloc=allocator_type())
Create a new raw_array instance with specified count, value, and allocator.
Definition raw_array.hpp:158
internal_base_type base_type
Underlying vector type.
Definition raw_array.hpp:123
internal_iterator iterator
Forward iterator for raw_array.
Definition raw_array.hpp:132
value_type * pointer
Pointer to element.
Definition raw_array.hpp:130
const base_type const_base_type
Const version of base_type.
Definition raw_array.hpp:124
raw_array(input_iterator_t first, input_iterator_t last, const allocator_type &alloc=allocator_type())
Create a new raw_array instance with specified first iterator, last iterator, and allocator.
Definition raw_array.hpp:168
static constexpr size_type bpos
Beginning position.
Definition raw_array.hpp:142
static constexpr size_type epos
End position.
Definition raw_array.hpp:143
value_type & reference
Reference to element.
Definition raw_array.hpp:128
std::reverse_iterator< const_iterator > const_reverse_iterator
Const reverse iterator.
Definition raw_array.hpp:135
typename base_type::allocator_type allocator_type
Allocator type.
Definition raw_array.hpp:125
type_t value_type
Type of the elements.
Definition raw_array.hpp:122
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator.
Definition raw_array.hpp:134
raw_array() noexcept=default
Create a new raw_array instance.
const value_type * const_pointer
Const pointer to element.
Definition raw_array.hpp:131
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
@ other
The operating system is other.
Definition platform_id.hpp:60
@ a
The A key.
Definition console_key.hpp:88
@ n
The N key.
Definition console_key.hpp:114
@ b
The B key.
Definition console_key.hpp:90
The xtd::collections::generic::helpers namespace contains helpers for generic collections,...
Definition allocator.hpp:14
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
virtual auto clear() -> void=0
Removes all items from the xtd::collections::generic::icollection <type_t>.
virtual auto count() const noexcept -> xtd::size=0
Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>.
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
const_reference front() const
Gets the first element.
Definition read_only_span.hpp:218
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition read_only_span.hpp:237
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:187
read_only_span< type_t, count > first() const
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:282
const_iterator end() const
Returns an iterator to the end.
Definition read_only_span.hpp:213
read_only_span< type_t, count > last() const
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:307
const_iterator cend() const
Returns an iterator to the end.
Definition read_only_span.hpp:190
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition read_only_span.hpp:233
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition read_only_span.hpp:194
const_reference back() const
Gets the last element.
Definition read_only_span.hpp:176
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
constexpr bool empty() const noexcept
Returns a value that indicates whether the current xtd::read_only_span <type_t> is empty.
Definition read_only_span.hpp:205
const_reverse_iterator crend() const
Returns a reverse iterator to the end.
Definition read_only_span.hpp:197