5#if !defined(__XTD_ARRAY_INTERNAL__)
6#error "Do not include this file: Internal use only. Include <xtd/array> or <xtd/array.h> instead."
26 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
31 comparer(
const comparer&) =
default;
32 comparer(comparer&&) =
default;
33 comparer& operator=(
const comparer& comparer) =
default;
34 comparer& operator=(comparer&&) =
default;
36 bool operator()(
const type_t& e1,
const type_t& e2)
const noexcept {
return comparer_ && comparer_->
compare(e1, e2) < 0;}
139 virtual bool empty() const noexcept {
return data_->items.empty();}
224 if (index >=
count()) __throw_index_out_of_range_exception(__FILE__, __LINE__, __func__);
225 return (
reference)data_->items.at(index);
232 if (index >=
count()) __throw_index_out_of_range_exception(__FILE__, __LINE__, __func__);
233 return (
reference)data_->items.at(index);
238 constexpr bool contains(
const type_t& value)
const noexcept override {
239 for (
const auto& item : data_->items)
240 if (
reinterpret_cast<const type_t&
>(item) == value)
return true;
247 if (
rank() != 1) __throw_rank_exception(__FILE__, __LINE__, __func__);
248 if (index +
length() >
array.size()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
249 for (
auto increment =
size_type {0}; increment <
length(); ++increment)
250 array[index + increment] =
at(increment);
261 bool equals(
const basic_array& rhs)
const noexcept override {
return data_->items == rhs.data_->items && data_->version == rhs.data_->version && data_->lower_bound == rhs.data_->lower_bound && data_->upper_bound == rhs.data_->upper_bound;}
273 if (version_ != items_.data_->version) __throw_invalid_operation_exception(
"Collection was modified; enumeration operation may not execute.", __FILE__, __LINE__, __func__);
274 return items_.at(index_);
277 bool move_next()
override {
278 if (version_ != items_.data_->version) __throw_invalid_operation_exception(
"Collection was modified; enumeration operation may not execute.", __FILE__, __LINE__, __func__);
279 return ++index_ < items_.count();
282 void reset()
override {
283 version_ = items_.data_->version;
284 index_ = basic_array::npos;
292 return {new_ptr<basic_array_enumerator>(*
this, data_->version)};
321 if (dimension >=
rank()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
322 return data_->lower_bound[dimension];
333 if (dimension >=
rank()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
334 return data_->upper_bound[dimension];
362 if (new_size ==
length())
return;
363 if (new_size >
max_size()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
365 data_->items.resize(new_size, value);
366 data_->upper_bound[0] = new_size - 1;
379 data_->items.swap(
other.data_->items);
419 if (index >
array.length() || index +
count >
array.length()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
422 for (
auto increment =
size_type {0}; increment <
count; ++increment) {
423 if (
array[index + increment] == value)
424 return index + increment;
440 if (index >
array.size() || index +
count >
array.size()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
441 if (
count == 0)
return;
442 ++
array.data_->version;
443 std::reverse(
array.data_->items.begin() + index,
array.data_->items.begin() + index +
count);
454 *data_ = *
other.data_;
466 data_->items =
items;
467 data_->upper_bound[0] = data_->items.size() - 1;
484 operator const base_type&()
const noexcept {
return data_->items;}
509 template<
typename type_array_t,
size_type rank_array_t,
typename allocator_array_t>
516 if (
array ==
null) __throw_argument_null_exception(__FILE__, __LINE__, __func__);
518 data_->upper_bound[0] = data_->items.size() - 1;
522 for (
const auto& value : enumerable)
523 data_->
items.push_back(value);
524 data_->lower_bound.push_back(0);
525 data_->upper_bound[0] = data_->items.size() - 1;
528 basic_array(
const std::vector<type_t>&
array) {
529 data_->items =
array;
530 data_->upper_bound[0] = data_->items.size() - 1;
533 basic_array(std::vector<type_t>&&
array) {
534 data_->items = std::move(
array);
535 data_->upper_bound[0] = data_->items.size() - 1;
538 basic_array(std::initializer_list<type_t> il) {
539 data_->items.assign(il.begin(), il.end());
540 data_->upper_bound[0] = data_->items.size() - 1;
543 basic_array(std::initializer_list<std::initializer_list<type_t>> il) {
544 for (
const std::initializer_list<type_t>& il1 : il)
546 data_->upper_bound[0] = il.size() - 1;
547 data_->lower_bound.push_back(0);
548 data_->upper_bound.push_back((*il.begin()).size() - 1);
551 basic_array(std::initializer_list<std::initializer_list<std::initializer_list<type_t>>> il) {
552 for (
const std::initializer_list<std::initializer_list<type_t>>& il1 : il)
553 for (const std::initializer_list<type_t>& il2 : il1)
555 data_->upper_bound[0] = il.size() - 1;
556 data_->lower_bound.push_back(0);
557 data_->upper_bound.push_back((*il.begin()).size() - 1);
558 data_->lower_bound.push_back(0);
559 data_->upper_bound.push_back((*(*il.begin()).begin()).size() - 1);
562 template<
typename iterator_t>
563 basic_array(iterator_t first, iterator_t last) {
564 data_->items.assign(first, last);
565 data_->lower_bound.push_back(0);
566 data_->upper_bound.push_back(data_->items.size() - 1);
569 void add(
const type_t& item)
override {}
570 void clear()
override {}
572 bool remove(
const type_t& item)
override {
return false;}
573 void remove_at(
size_type index)
override {}
575 typename base_type::iterator to_base_type_iterator(
iterator value)
noexcept {
576 if (value ==
begin())
return data_->items.begin();
577 if (value ==
end())
return data_->items.end();
578 return data_->items.begin() + (value -
begin());
581 iterator to_iterator(
typename base_type::iterator value)
noexcept {
582 if (value == data_->items.begin())
return begin();
583 if (value == data_->items.end())
return end();
584 return begin() + (value - data_->items.begin());
590 std::vector<size_type> lower_bound {0};
591 std::vector<size_type> upper_bound {std::numeric_limits<size_type>::max()};
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition __array_definition.h:49
Abstract object that represent array.
Definition array_abstract_object.h:25
Base object that represent array.
Definition basic_array.h:27
typename base_type::const_reverse_iterator const_reverse_iterator
Represents the const reverse iterator of array value type.
Definition basic_array.h:71
const value_type & const_reference
Represents the const reference of array value type.
Definition basic_array.h:59
constexpr xtd::int64 get_long_length(size_type dimension) const
Gets a 64-bit integer that represents the total number of elements in all the dimensions of the array...
Definition basic_array.h:311
virtual const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition basic_array.h:198
virtual bool empty() const noexcept
Checks if the container has no elements, i.e. whether xtd::array::begin() == xtd::array::end().
Definition basic_array.h:139
virtual size_type rank() const noexcept
Gets the rank (number of dimensions) of the array.
Definition basic_array.h:189
virtual const_pointer data() const noexcept
Returns pointer to the underlying array serving as element storage.
Definition basic_array.h:135
typename xtd::collections::generic::ilist< type_t >::iterator iterator
Represents the iterator of array value type.
Definition basic_array.h:65
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition basic_array.h:111
xtd::ptrdiff difference_type
Represents the array difference type (usually xtd::ptrdiff).
Definition basic_array.h:55
virtual reference front()
Returns a reference to the first element in the container.
Definition basic_array.h:151
size_type count() const noexcept override
Gets the number of elements contained in the xtd::array <type_t>.
Definition basic_array.h:116
typename xtd::collections::generic::ilist< type_t >::const_iterator const_iterator
Represents the const iterator of array value type.
Definition basic_array.h:67
virtual const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition basic_array.h:207
virtual reference at(size_type index)
Returns a reference to the element at specified location pos, with bounds checking.
Definition basic_array.h:223
void set_value(const type_t &value, const xtd::array_< size_type > &indexes)
Sets a value to the element at the specified position in the multidimensional array.
Definition basic_array.h:373
void resize(size_type new_size)
Resizes the container to contain count elements, does nothing if count == size(). @param new_size The...
Definition basic_array.h:353
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition basic_array.h:260
xtd::collections::generic::helpers::allocator< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type > allocator_type
Represents the array allocator type.
Definition basic_array.h:49
constexpr size_type get_length(size_type dimension) const
Gets the total number of elements in all the dimensions of the array.
Definition basic_array.h:302
virtual xtd::int64 long_length()
Gets a 64-bit integer that represents the total number of elements in all the dimensions of the array...
Definition basic_array.h:178
typename base_type::reverse_iterator reverse_iterator
Represents the reverse iterator of array value type.
Definition basic_array.h:69
const value_type * const_pointer
Represents the const pointer of array value type.
Definition basic_array.h:63
virtual const_reference back() const
Returns a reference to the last element in the container.
Definition basic_array.h:96
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type xtd::size.
Definition basic_array.h:78
static size_type index_of(const basic_array &array, const value_type &value) noexcept
Determines the index of a specific item in the array specified.
Definition basic_array.h:395
value_type * pointer
Represents the pointer of array value type.
Definition basic_array.h:61
virtual pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition basic_array.h:131
bool is_synchronized() const noexcept override
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is sync...
Definition basic_array.h:159
value_type & reference
Represents the reference of array value type.
Definition basic_array.h:57
size_type index_of(const type_t &value) const noexcept override
Determines the index of a specific item in the xtd::array <type_t>.
Definition basic_array.h:346
constexpr bool contains(const type_t &value) const noexcept override
Determines whether an element is in the array.
Definition basic_array.h:238
xtd::collections::generic::enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through a collection.
Definition basic_array.h:267
void copy_to(xtd::array< type_t > &array, size_type index) const override
Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array,...
Definition basic_array.h:244
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition basic_array.h:143
constexpr size_type get_lower_bound(size_type dimension) const
Gets the lower bound of the specified dimension in the array.
Definition basic_array.h:320
virtual size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition basic_array.h:182
void resize(size_type new_size, value_type value)
Resizes the container to contain count elements, does nothing if count == size(). @param new_size The...
Definition basic_array.h:361
iterator begin() noexcept override
Returns an iterator to the first element of the enumarable.
Definition basic_array.h:103
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition basic_array.h:100
void copy_to(xtd::array< type_t > &array, xtd::int64 index) const
Copies all the elements of the current one-dimensional array to the specified one-dimensional array s...
Definition basic_array.h:258
type_t value_type
Represents the array value type.
Definition basic_array.h:47
virtual void fill(const value_type &value) noexcept
Assigns the value to all elements in the container.
Definition basic_array.h:265
basic_array & operator=(const basic_array &other)
Copy assignment operator. Replaces the contents with a copy of the contents of other.
Definition basic_array.h:453
virtual reverse_iterator rbegin() noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition basic_array.h:194
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition basic_array.h:146
virtual const_reference at(size_type index) const
Returns a reference to the element at specified location pos, with bounds checking.
Definition basic_array.h:231
virtual size_type length() const noexcept
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.h:174
virtual reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition basic_array.h:203
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition basic_array.h:163
const value_type & get_value(const xtd::array_< size_type > &indexes) const
Gets the value at the specified position in the multidimensional array. The indexes are specified as ...
constexpr size_type get_upper_bound(size_type dimension) const
Gets the upper bound of the specified dimension in the array.
Definition basic_array.h:332
virtual const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition basic_array.h:126
virtual void swap(basic_array &other) noexcept
Exchanges the contents and capacity of the container with those of other. Does not invoke any move,...
Definition basic_array.h:377
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location index.
Definition basic_array.h:475
type_t & operator()(const xtd::array_< size_type > &indexes)
Gets the value at the specified position in the multidimensional array. The indexes are specified as ...
virtual const_reference front() const
Returns a reference to the first element in the container.
Definition basic_array.h:155
const type_t & operator()(const xtd::array_< size_type > &indexes) const
Gets the value at the specified position in the multidimensional array. The indexes are specified as ...
bool is_fixed_size() const noexcept override
Gets a value indicating whether the xtd::collections::generic::ilist <type_t> has a fixed size.
Definition basic_array.h:157
static void reverse(basic_array &array) noexcept
Reverses the order of the elements in the entire xtd::basic_array.
Definition basic_array.h:432
std::vector< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type, allocator_type > base_type
Represents the array base type.
Definition basic_array.h:51
static size_type index_of(const basic_array &array, const value_type &value, size_type index, size_type count)
Determines the index of a specific item in the array specified.
Definition basic_array.h:418
static size_type index_of(const basic_array &array, const value_type &value, size_type index)
Determines the index of a specific item in the array specified.
Definition basic_array.h:406
virtual reference back()
Returns a reference to the last element in the container.
Definition basic_array.h:92
bool is_read_only() const noexcept override
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
Definition basic_array.h:158
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition basic_array.h:107
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition basic_array.h:166
const xtd::object & sync_root() const noexcept override
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
Definition basic_array.h:213
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::array::begin(),...
Definition basic_array.h:211
static void reverse(basic_array &array, size_type index, size_type count)
Reverses the order of the elements in the specified range.
Definition basic_array.h:439
virtual const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition basic_array.h:121
xtd::size size_type
Represents the array size type (usually xtd::size).
Definition basic_array.h:53
Represents text as a sequence of character units.
Definition basic_string.h:79
virtual const_iterator cend() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.h:209
virtual const_iterator cbegin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.h:205
virtual const_iterator end() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.h:213
virtual const_iterator begin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.h:198
Supports a simple iteration over a generic collection.
Definition enumerator.h:31
Exposes a method that compares two objects.
Definition icomparer.h:30
virtual int32 compare(const type_t &x, const type_t &y) const =0
Compares two entities and returns a value indicating whether one is less than, equal to,...
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.h:35
Supports a simple iteration over a generic collection.
Definition ienumerator.h:58
Represents a collection of objects that can be individually accessed by index.
Definition ilist.h:41
typename icollection< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.h:47
typename icollection< type_t >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.h:49
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:114
std::allocator< type_t > allocator
Represent an allocator alias.
Definition allocator.h:35
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27
int64_t int64
Represents a 64-bit signed integer.
Definition int64.h:23
null_ptr null
Represents a null pointer value.
size_t size
Represents a size of any object in bytes.
Definition size.h:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.h:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.h:23
std::type_info type
Stores information about a type.
Definition type.h:23
@ other
The operating system is other.
@ insert
The INS (INSERT) key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
std::vector< type_t > array
Definition __array_definition.h:18