5#if !defined(__XTD_ARRAY_INTERNAL__)
6#error "Do not include this file: Internal use only. Include <xtd/array> or <xtd/array.hpp> instead."
26 template<
typename type_t,
typename allocator_t = xtd::collections::
generic::helpers::allocator<type_t>>
61 basic_array(basic_array&& array) =
default;
62 basic_array(
const basic_array & array) {
if (array.data_) *data_ = *array.data_;}
72 [[nodiscard]]
auto count() const noexcept ->
size_type override {
return data_->items.size();}
86 [[nodiscard]]
auto is_fixed_size() const noexcept ->
bool override {
return true;}
91 [[nodiscard]]
auto is_read_only() const noexcept ->
bool override {
return false;}
111 [[nodiscard]]
virtual auto items() const noexcept -> const
base_type& {
return data_->items;}
122 [[nodiscard]]
virtual auto length() const noexcept ->
size_type {
return data_->items.size();}
160 [[nodiscard]]
auto sync_root() const noexcept -> const
xtd::
object&
override {
return data_->sync_root;}
168 [[nodiscard]]
auto contains(
const type_t& value)
const noexcept ->
bool override {
169 for (
const auto& item : data_->items)
186 return copy_to(0, array, array_index);
194 return copy_to(compute_index(
self_, indexes), array, array_index);
222 for (
auto i = index;
i < (index +
count); ++
i)
223 array[array_index++] =
self_[
i];
229 [[nodiscard]]
auto equals(
const object & obj)
const noexcept ->
bool override {
return dynamic_cast<const basic_array<value_type>*
>(&obj) &&
equals(
static_cast<const basic_array<value_type>&
>(obj));}
234 [[nodiscard]]
auto equals(
const basic_array & rhs)
const noexcept ->
bool override {
235 if (
count() != rhs.count())
return false;
238 return data_->lower_bound == rhs.data_->lower_bound && data_->upper_bound == rhs.data_->upper_bound;
244 for (
auto& item : data_->items)
252 [[nodiscard]]
const value_type& current()
const override {
255 return items_[index_];
258 bool move_next()
override {
260 return ++index_ < items_.count();
263 void reset()
override {
264 version_ = items_.data_->items.version();
265 index_ = basic_array::npos;
270 const basic_array& items_;
307 return data_->lower_bound[dimension];
319 return data_->upper_bound[dimension];
346 for (
auto increment = index; increment < (index +
count); ++increment)
365 if (new_size ==
length())
return;
368 data_->items.resize(new_size, value);
369 data_->upper_bound[0] = new_size - 1;
394 template<
typename comparison_t>
396 data_->items.increment_version();
397 std::sort(data_->items.begin(), data_->items.end(), [&](
const type_t&
x,
const type_t&
y) {return comparison(x, y) < 0;});
421 data_->items.increment_version();
437 auto operator =(const basic_array &
other) -> basic_array& {
438 *data_ = *
other.data_;
449 data_->items =
items;
450 data_->upper_bound[0] = data_->items.size() - 1;
460 return data_->items.at(index);
468 return data_->items.at(index);
473 [[nodiscard]]
operator const base_type&()
const noexcept {
return data_->items;}
476 [[nodiscard]]
operator base_type&()
noexcept {
return data_->items;}
498 template<
typename type_array_t,
size_type rank_array_t,
typename allocator_array_t>
501 basic_array() =
default;
502 explicit basic_array(
const array < size_type, 1 >& lengths);
503 basic_array(
const array < size_type, 1 >& lengths,
const value_type & value);
507 data_->upper_bound[0] = data_->items.size() - 1;
509 explicit basic_array(
const xtd::collections::generic::ienumerable < type_t >& enumerable) {
510 for (
const auto& value : enumerable)
511 data_->items.push_back(value);
512 data_->upper_bound[0] = data_->items.size() - 1;
514 explicit basic_array(
const xtd::collections::generic::ilist < type_t >&
items) {
515 data_->items.reserve(
items.count());
516 for (
const auto& value :
items)
517 data_->items.push_back(value);
518 data_->upper_bound[0] = data_->items.size() - 1;
521 template<
typename input_iterator_t>
522 basic_array(input_iterator_t
first, input_iterator_t
last) {
524 data_->upper_bound[0] = data_->items.size() - 1;
527 basic_array(
const std::vector < type_t >&
items) {
528 data_->items.assign(
items.begin(),
items.end());
529 data_->upper_bound[0] = data_->items.size() - 1;
532 basic_array(
const std::vector < std::vector < type_t>>&
items) {
533 for (
const std::vector < type_t >& items1 :
items)
534 data_->items.insert(data_->items.end(), items1.begin(), items1.end());
535 data_->upper_bound[0] =
items.size() - 1;
536 data_->lower_bound.push_back(0);
537 data_->upper_bound.push_back((*
items.begin()).size() - 1);
540 basic_array(
const std::vector < std::vector < std::vector<type_t>>>&
items) {
541 for (
const std::vector < std::vector < type_t>>& items1 :
items)
542 for (
const std::vector < type_t >& items2 : items1)
543 data_->items.insert(data_->items.end(), items2.begin(), items2.end());
544 data_->upper_bound[0] =
items.size() - 1;
545 data_->lower_bound.push_back(0);
546 data_->upper_bound.push_back((*
items.begin()).size() - 1);
547 data_->lower_bound.push_back(0);
548 data_->upper_bound.push_back((*(*
items.begin()).begin()).size() - 1);
551 basic_array(std::initializer_list < type_t > il) {
552 data_->items.assign(il.begin(), il.end());
553 data_->upper_bound[0] = data_->items.size() - 1;
556 basic_array(std::initializer_list < std::initializer_list < type_t>> il) {
557 for (
const std::initializer_list < type_t >& il1 : il)
558 data_->items.insert(data_->items.end(), il1.begin(), il1.end());
559 data_->upper_bound[0] = il.size() - 1;
560 data_->lower_bound.push_back(0);
561 data_->upper_bound.push_back((*il.begin()).size() - 1);
564 basic_array(std::initializer_list < std::initializer_list < std::initializer_list<type_t>>> il) {
565 for (
const std::initializer_list < std::initializer_list < type_t>>& il1 : il)
566 for (
const std::initializer_list < type_t >& il2 : il1)
567 data_->items.insert(data_->items.end(), il2.begin(), il2.end());
568 data_->upper_bound[0] = il.size() - 1;
569 data_->lower_bound.push_back(0);
570 data_->upper_bound.push_back((*il.begin()).size() - 1);
571 data_->lower_bound.push_back(0);
572 data_->upper_bound.push_back((*(*il.begin()).begin()).size() - 1);
575 auto add(
const type_t& item) ->
void override {}
579 template<
typename value_t>
580 [[nodiscard]]
static auto compute_index(
const xtd::basic_array<value_t>&
items,
const xtd::array<size_type>& indexes) ->
xtd::usize;
581 template<
typename value_t>
584 auto insert(
size_type index,
const type_t& value) ->
void override {}
586 auto remove(
const type_t& item) ->
bool override {
return false;}
588 auto remove_at(
size_type index) ->
void override {}
592 if (
count == 0)
return;
593 data_->items.increment_version();
594 std::reverse(data_->items.begin() + index, data_->items.begin() + index +
count);
597 template<
typename value_t>
601 xtd::collections::generic::helpers::raw_array < value_type > items;
602 std::vector < size_type > lower_bound {0};
603 std::vector < size_type > upper_bound {std::numeric_limits < size_type >::max()};
Abstract object that represent array.
Definition array_abstract_object.hpp:25
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Base object that represent array.
Definition basic_array.hpp:27
const value_type & const_reference
Represents the const reference of array value type.
Definition basic_array.hpp:45
auto is_read_only() const noexcept -> bool override
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
Definition basic_array.hpp:91
xtd::collections::generic::helpers::allocator< value_type > allocator_type
Represents the array allocator type.
Definition basic_array.hpp:35
auto is_synchronized() const noexcept -> bool override
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is sync...
Definition basic_array.hpp:107
auto copy_to(xtd::array< type_t > &array) const -> void
Copies the entire xtd::array <type_t> to a compatible one-dimensional array.
Definition basic_array.hpp:177
auto is_fixed_size() const noexcept -> bool override
Gets a value indicating whether the xtd::collections::generic::ilist <type_t> has a fixed size.
Definition basic_array.hpp:86
auto get_value(const xtd::array< size_type > &indexes) const -> const value_type &
Gets the value at the specified position in the multidimensional array. The indexes are specified as ...
virtual auto data() const noexcept -> const_pointer
Returns pointer to the underlying array serving as element storage.
Definition basic_array.hpp:81
auto copy_to(const xtd::array< size_type > &indexes, xtd::array< type_t > &array, size_type array_index) const -> void
Copies the elements of the xtd::array <type_t> from a specified index to an xtd::array,...
Definition basic_array.hpp:193
auto copy_to(const size_type index, xtd::array< type_t > &array, size_type array_index) const -> void
Copies the elements of the xtd::array <type_t> from a specified index to an xtd::array,...
Definition basic_array.hpp:210
virtual auto rank() const noexcept -> size_type
Gets the rank (number of dimensions) of the array.
Definition basic_array.hpp:137
typename xtd::collections::generic::ienumerable< type_t >::const_iterator const_iterator
Represents the const iterator of array value type.
Definition basic_array.hpp:53
xtd::ptrdiff difference_type
Represents the array difference type (usually xtd::ptrdiff).
Definition basic_array.hpp:41
auto get_lengths() const -> xtd::array< size_type, 1 >
Gets an array of the number of elements of all the dimensions of the array.
xtd::usize size_type
Represents the array size type (usually xtd::usize).
Definition basic_array.hpp:39
auto sync_root() const noexcept -> const xtd::object &override
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
Definition basic_array.hpp:160
auto to_string() const noexcept -> xtd::string override
Returns a xtd::string that represents the current object.
auto index_of(const type_t &value, size_type index) const -> size_type
Determines the index of a specific item in the xtd::basic_array <type_t>.
Definition basic_array.hpp:337
virtual auto items() const noexcept -> const base_type &
Returns the underlying base type items.
Definition basic_array.hpp:111
constexpr auto get_length(size_type dimension) const -> size_type
Gets the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:283
const value_type * const_pointer
Represents the const pointer of array value type.
Definition basic_array.hpp:49
typename xtd::collections::generic::helpers::raw_array< value_type >::reverse_iterator reverse_iterator
Represents the reverse iterator of array value type.
Definition basic_array.hpp:55
value_type * pointer
Represents the pointer of array value type.
Definition basic_array.hpp:47
virtual auto long_length() -> xtd::int64
Gets a 64-bit integer that represents the total number of elements in all the dimensions of the array...
Definition basic_array.hpp:126
constexpr auto get_long_length(size_type dimension) const -> xtd::int64
Gets a 64-bit integer that represents the total number of elements in all the dimensions of the array...
Definition basic_array.hpp:296
value_type & reference
Represents the reference of array value type.
Definition basic_array.hpp:43
auto operator()(const xtd::array< size_type > &indexes) -> type_t &
Gets the value at the specified position in the multidimensional array. The indexes are specified as ...
auto count() const noexcept -> size_type override
Gets the number of elements contained in the xtd::array <type_t>.
Definition basic_array.hpp:72
auto copy_to(const xtd::array< size_type > &indexes, xtd::array< type_t > &array, size_type array_index, size_type count) const -> void
Copies the elements of the xtd::array <type_t> from a specified index to an xtd::array,...
Definition basic_array.hpp:202
type_t value_type
Represents the array value type.
Definition basic_array.hpp:33
auto set_value(const type_t &value, const xtd::array< size_type > &indexes) -> void
Determines the index of a specific item in the xtd::basic_array <type_t>.
Definition basic_array.hpp:376
virtual auto length() const noexcept -> size_type
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:122
typename xtd::collections::generic::helpers::raw_array< value_type, allocator_type >::base_type base_type
Represents the array base type.
Definition basic_array.hpp:37
auto sort(xtd::usize index, xtd::usize count, const xtd::collections::generic::icomparer< type_t > &comparer) -> basic_array< type_t > &
Sorts the elements in a range of elements in xtd::basic_array <type_t> using the specified comparer.
Definition basic_array.hpp:419
auto operator[](size_type index) const -> const_reference override
Returns a reference to the element at specified location index.
Definition basic_array.hpp:458
auto contains(const type_t &value) const noexcept -> bool override
Determines whether an element is in the array.
Definition basic_array.hpp:168
typename xtd::collections::generic::helpers::raw_array< value_type >::const_reverse_iterator const_reverse_iterator
Represents the const reverse iterator of array value type.
Definition basic_array.hpp:57
constexpr auto get_lower_bound(size_type dimension) const -> size_type
Gets the lower bound of the specified dimension in the array.
Definition basic_array.hpp:305
auto copy_to(xtd::array< type_t > &array, size_type array_index) const -> void override
Copies the elements of the xtd::array <type_t> to an xtd::array, starting at a particular xtd::array ...
Definition basic_array.hpp:185
virtual auto fill(const value_type &value) noexcept -> void
Assigns the value to all elements in the container.
Definition basic_array.hpp:243
auto operator()(const xtd::array< size_type > &indexes) const -> const type_t &
Gets the value at the specified position in the multidimensional array. The indexes are specified as ...
virtual auto max_length() const noexcept -> size_type
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition basic_array.hpp:130
auto equals(const object &obj) const noexcept -> bool override
Determines whether this instance and a specified object, which must also be a xtd::basic_array object...
Definition basic_array.hpp:229
typename xtd::collections::generic::ienumerable< type_t >::iterator iterator
Represents the iterator of array value type.
Definition basic_array.hpp:51
auto operator=(const basic_array &other) -> basic_array &
Copy assignment operator. Replaces the contents with a copy of the contents of other.
Definition basic_array.hpp:437
auto sort() -> basic_array< type_t > &
Sorts the elements in the entire xtd::basic_array <type_t> using the default comparer.
Definition basic_array.hpp:387
auto index_of(const type_t &value) const noexcept -> size_type override
Determines the index of a specific item in the xtd::array <type_t>.
Definition basic_array.hpp:331
auto equals(const basic_array &rhs) const noexcept -> bool override
Determines whether this instance and another specified xtd::basic_array object have the same value.
Definition basic_array.hpp:234
auto sort(comparison_t &&comparison) -> basic_array< type_t > &
Sorts the elements in the entire xtd::basic_array <type_t> using the specified xtd::comparison <type_...
Definition basic_array.hpp:395
virtual auto data() noexcept -> pointer
Returns pointer to the underlying array serving as element storage.
Definition basic_array.hpp:77
constexpr auto get_upper_bound(size_type dimension) const -> size_type
Gets the upper bound of the specified dimension in the array.
Definition basic_array.hpp:317
virtual auto items() noexcept -> base_type &
Returns the underlying base type items.
Definition basic_array.hpp:114
auto sort(const xtd::collections::generic::icomparer< type_t > &comparer) -> basic_array< type_t > &
Sorts the elements in the entire xtd::basic_array <type_t> using the specified comparer.
Definition basic_array.hpp:407
auto copy_to(const size_type index, xtd::array< type_t > &array, size_type array_index, size_type count) const -> void
Copies the elements of the xtd::array <type_t> from a specified index to an xtd::array,...
Definition basic_array.hpp:219
static const comparer< xtd::any_object > default_comparer
Definition comparer.hpp:50
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:32
internal_base_type base_type
Underlying vector type.
Definition raw_array.hpp:123
std::reverse_iterator< const_iterator > const_reverse_iterator
Const reverse iterator.
Definition raw_array.hpp:135
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator.
Definition raw_array.hpp:134
Exposes a method that compares two objects.
Definition icomparer.hpp:30
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
typename xtd::collections::generic::extensions::enumerable_iterators< xtd::any_object, xtd::collections::generic::ienumerable< xtd::any_object > >::const_iterator const_iterator
Definition ienumerable.hpp:50
typename xtd::collections::generic::extensions::enumerable_iterators< xtd::any_object, xtd::collections::generic::ienumerable< xtd::any_object > >::iterator iterator
Definition ienumerable.hpp:48
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:115
xtd::delegate< int32(type_t x, type_t y)> comparison
Represents the method that compares two objects of the same type.
Definition comparison.hpp:33
std::allocator< type_t > allocator
Represent an allocator alias.
Definition allocator.hpp:38
@ argument
The argument is not valid.
Definition exception_case.hpp:31
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:61
@ out_of_memory
Out of memory.
Definition exception_case.hpp:87
@ argument_null
The argument is null.
Definition exception_case.hpp:33
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
@ invalid_operation
The operation is not valid.
Definition exception_case.hpp:65
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
constexpr xtd::usize npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
null_ptr null
Represents a null pointer value.
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
@ other
The operating system is other.
Definition platform_id.hpp:60
@ y
The Y key.
Definition console_key.hpp:136
@ i
The I key.
Definition console_key.hpp:104
@ x
The X key.
Definition console_key.hpp:134
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
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
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
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
xtd::usize size_type
Represents the read_only_span size type (usually xtd::usize).
Definition read_only_span.hpp:62
Implements a function object for performing comparisons. Unless specialised, invokes operator== on ty...
Definition equator.hpp:39
Implements a function object for compare data.
Definition lesser.hpp:39
Represents a value_type struct.
Definition value_type.hpp:34