xtd 0.2.0
Loading...
Searching...
No Matches
xtd::basic_array< type_t, allocator_t > Class Template Reference
Inheritance diagram for xtd::basic_array< type_t, allocator_t >:
xtd::array_abstract_object xtd::iequatable< type_t > xtd::abstract_object xtd::interface xtd::extensions::equality_operators< type_t, iequatable< type_t > > xtd::object xtd::array< xtd::string > xtd::array< xtd::diagnostics::stack_frame > xtd::array< xtd::drawing::color > xtd::array< xtd::array< bool > > xtd::array< xtd::drawing::point > xtd::array< xtd::size > xtd::array< item > xtd::array< xtd::forms::shadow >

Definition

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
class xtd::basic_array< type_t, allocator_t >

Base object that represent array.

Definition
template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
class basic_array : public xtd::array_object, public xtd::collections::generic::ilist<type_t>, public xtd::iequatable<basic_array<type_t, allocator_t>>;
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Header
#include <xtd/array>
Namespace
xtd
Library
xtd.core

Public Aliases

using value_type
 Represents the array value type.
using allocator_type
 Represents the array allocator type.
using base_type
 Represents the array base type.
using size_type
 Represents the array size type (usually xtd::size).
using difference_type
 Represents the array difference type (usually xtd::ptrdiff).
using reference
 Represents the reference of array value type.
using const_reference
 Represents the const reference of array value type.
using pointer
 Represents the pointer of array value type.
using const_pointer
 Represents the const pointer of array value type.
using iterator
 Represents the iterator of array value type.
using const_iterator
 Represents the const iterator of array value type.
using reverse_iterator
 Represents the reverse iterator of array value type.
using const_reverse_iterator
 Represents the const reverse iterator of array value type.

Public Properties

auto count () const noexcept -> size_type override
 Gets the number of elements contained in the xtd::array <type_t>.
virtual auto data () noexcept -> pointer
 Returns pointer to the underlying array serving as element storage.
virtual auto data () const noexcept -> const_pointer
 Returns pointer to the underlying array serving as element storage.
auto is_fixed_size () const noexcept -> bool override
 Gets a value indicating whether the xtd::collections::generic::ilist <type_t> has a fixed size.
auto is_read_only () const noexcept -> bool override
 Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
auto is_synchronized () const noexcept -> bool override
 Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe).
virtual auto items () const noexcept -> const base_type &
 Returns the underlying base type items.
virtual auto items () noexcept -> base_type &
 Returns the underlying base type items.
virtual auto length () const noexcept -> size_type
 Gets a size that represents the total number of elements in all the dimensions of the array.
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.
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 implementation limitations, i.e. std::distance(xtd::array::begin(), xtd::array::end()) for the largest container.
virtual auto rank () const noexcept -> size_type
 Gets the rank (number of dimensions) of the array.
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::icollection <type_t>.

Public Methods

auto contains (const type_t &value) const noexcept -> bool override
 Determines whether an element is in the array.
auto copy_to (xtd::array< type_t > &array) const -> void
 Copies the entire xtd::array <type_t> to a compatible one-dimensional array.
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 index.
auto copy_to (const xtd::array< size_type > &indexes, xtd::array< type_t > &array, size_type array_index) const -> void
auto copy_to (const xtd::array< size_type > &indexes, xtd::array< type_t > &array, size_type array_index, size_type count) const -> void
auto copy_to (const size_type index, xtd::array< type_t > &array, size_type array_index) const -> void
auto copy_to (const size_type index, xtd::array< type_t > &array, size_type array_index, size_type count) const -> void
auto equals (const object &obj) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
auto equals (const basic_array &rhs) const noexcept -> bool override
virtual auto fill (const value_type &value) noexcept -> void
 Assigns the value to all elements in the container.
auto get_enumerator () const noexcept -> xtd::collections::generic::enumerator< value_type > override
constexpr auto get_length (size_type dimension) const -> size_type
 Gets the total number of elements in all the dimensions of the array.
auto get_lengths () const -> xtd::array< size_type, 1 >
 Gets an array of the number of elements of all the dimensions of the array.
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.
constexpr auto get_lower_bound (size_type dimension) const -> size_type
 Gets the lower bound of the specified dimension in the array.
constexpr auto get_upper_bound (size_type dimension) const -> size_type
 Gets the upper bound of the specified dimension in the array.
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 32-bit integers array.
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>.
auto index_of (const type_t &value, size_type index) const -> size_type
auto index_of (const type_t &value, size_type index, size_type count) const -> size_type
auto set_value (const type_t &value, const xtd::array< size_type > &indexes) -> void
 Resizes the container to contain count elements, does nothing if count == length(). @param new_size The new size of the container. @exception xtd::argument_out_of_range_exception xtd::collections::generic::list::capacity is set to a value that is less than xtd::collections::generic::list::count. @remarks If the current size is greater than count, the container is reduced to its first count elements. @remarks If the current size is less than count`, additional default-inserted elements are appended. */ auto resize(size_type new_size) -> void {resize(new_size, value_type {});}.
auto sort () -> basic_array< type_t > &
 Sorts the elements in the entire xtd::collections::generic::list <type_t> using the default comparer.
template<typename comparison_t>
auto sort (comparison_t &&comparison) -> basic_array< type_t > &
 Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified xtd::comparison <type_t>.
auto sort (const xtd::collections::generic::icomparer< type_t > &comparer) -> basic_array< type_t > &
 Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified comparer.
auto sort (xtd::size index, xtd::size count, const xtd::collections::generic::icomparer< type_t > &comparer) -> basic_array< type_t > &
 Sorts the elements in a range of elements in xtd::collections::generic::list <type_t> using the specified comparer.
auto to_string () const noexcept -> xtd::string override
 Returns a xtd::string that represents the current object.

Public Operators

auto operator= (const basic_array &other) -> basic_array &
 Copy assignment operator. Replaces the contents with a copy of the contents of other.
auto operator= (basic_array &&other) noexcept -> basic_array &=default
 Move assignment operator. Replaces the contents with those of other using move semantics (i.e. the data in other is moved from other into this container). other is in a valid but unspecified state afterwards.
auto operator= (std::initializer_list< type_t > &items) -> basic_array &
 Replaces the contents with those identified by initializer list ilist.
auto operator[] (size_type index) const -> const_reference override
 Returns a reference to the element at specified location index.
auto operator[] (size_type index) -> reference override
 Returns a reference to the element at specified location index.
 operator const base_type & () const noexcept
 Returns a reference to the underlying base type.
 operator base_type & () noexcept
 Returns a reference to the underlying base type.
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 a 32-bit integer array.
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 a 32-bit integer array.

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
virtual xtd::size get_hash_code () const noexcept
 Serves as a hash function for a particular type.
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
template<typename object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
virtual bool equals (const type_t &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
template<typename object_a_t, typename object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 abstract_object ()=default
 Initializes a new instance of the xtd::abstract_object class.

Member Typedef Documentation

◆ value_type

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::value_type

Represents the array value type.

◆ allocator_type

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::allocator_type

Represents the array allocator type.

◆ base_type

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::base_type

Represents the array base type.

◆ size_type

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::size_type

Represents the array size type (usually xtd::size).

◆ difference_type

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::difference_type

Represents the array difference type (usually xtd::ptrdiff).

◆ reference

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::reference

Represents the reference of array value type.

◆ const_reference

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::const_reference

Represents the const reference of array value type.

◆ pointer

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::pointer

Represents the pointer of array value type.

◆ const_pointer

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::const_pointer

Represents the const pointer of array value type.

◆ iterator

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::iterator

Represents the iterator of array value type.

◆ const_iterator

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::const_iterator

Represents the const iterator of array value type.

◆ reverse_iterator

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::reverse_iterator

Represents the reverse iterator of array value type.

◆ const_reverse_iterator

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
using xtd::basic_array< type_t, allocator_t >::const_reverse_iterator

Represents the const reverse iterator of array value type.

Member Function Documentation

◆ count()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::count ( ) const -> size_type
inlinenodiscardoverridenoexcept

Gets the number of elements contained in the xtd::array <type_t>.

Returns
The number of elements contained in the xtd::array <type_t>.
Remarks
Retrieving the value of this property is an O(1) operation; setting the property is an O(n) operation, where n is the new capacity.

◆ data() [1/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
virtual auto xtd::basic_array< type_t, allocator_t >::data ( ) -> pointer
inlinenodiscardvirtualnoexcept

Returns pointer to the underlying array serving as element storage.

Returns
Pointer to the underlying element storage. For non-empty containers, the returned pointer compares equal to the address of the first element.
Remarks
The pointer is such that range [xtd::array::data(), xtd::array::data() + xtd::array::size()) is always a valid range, even if the container is empty (xtd::array::data() is not dereferenceable in that case).

◆ data() [2/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
virtual auto xtd::basic_array< type_t, allocator_t >::data ( ) const -> const_pointer
inlinenodiscardvirtualnoexcept

Returns pointer to the underlying array serving as element storage.

Returns
Pointer to the underlying element storage. For non-empty containers, the returned pointer compares equal to the address of the first element.
Remarks
The pointer is such that range [xtd::array::data(), xtd::array::data() + xtd::array::size()) is always a valid range, even if the container is empty (xtd::array::data() is not dereferenceable in that case).

◆ is_fixed_size()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::is_fixed_size ( ) const -> bool
inlinenodiscardoverridenoexcept

Gets a value indicating whether the xtd::collections::generic::ilist <type_t> has a fixed size.

Returns
true if the xtd::collections::generic::ilist <type_t> has a fixed size; otherwise, false.
Remarks
A collection with a fixed size does not allow the addition or removal of elements after the collection is created, but it allows the modification of existing elements.

◆ is_read_only()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::is_read_only ( ) const -> bool
inlinenodiscardoverridenoexcept

Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.

Returns
true if the xtd::collections::generic::icollection <type_t> is read-only; otherwise, false.
Remarks
A collection that is read-only does not allow the addition or removal of elements after the collection is created. Note that read-only in this context does not indicate whether individual elements of the collection can be modified, since the xtd::collections::generic::icollection <type_t> interface only supports addition and removal operations. For example, the xtd::collections::generic::icollection::is_read_only property of an array that is cast or converted to an xtd::collections::generic::icollection <type_t> object returns true, even though individual array elements can be modified.

◆ is_synchronized()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::is_synchronized ( ) const -> bool
inlinenodiscardoverridenoexcept

Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe).

Returns
true if access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe); otherwise, false.
Remarks
xtd::collections::generic::icollection::sync_root returns an object, which can be used to synchronize access to the xtd::collections::generic::icollection <type_t>.
Most collection classes in the xtd::collections namespace also implement a synchronized method, which provides a synchronized wrapper around the underlying collection.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
The following code example shows how to lock the collection using the xtd::collections::generic::icollection::sync_root property during the entire enumeration.
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
for (const auto& item : my_collection) {
// Insert your code here.
}
}
#define lock_(object)
The lock_ keyword marks a statement block as a critical section by obtaining the mutual-exclusion loc...
Definition lock.hpp:68

◆ items() [1/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
virtual auto xtd::basic_array< type_t, allocator_t >::items ( ) const -> const base_type &
inlinenodiscardvirtualnoexcept

Returns the underlying base type items.

Returns
The underlying base type items.

◆ items() [2/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
virtual auto xtd::basic_array< type_t, allocator_t >::items ( ) -> base_type &
inlinenodiscardvirtualnoexcept

Returns the underlying base type items.

Returns
The underlying base type items.

◆ length()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
virtual auto xtd::basic_array< type_t, allocator_t >::length ( ) const -> size_type
inlinenodiscardvirtualnoexcept

Gets a size that represents the total number of elements in all the dimensions of the array.

Returns
A size that represents the total number of elements in all the dimensions of the array; zero if there are no elements in the array.
Remarks
Retrieving the value of this property is an O(1) operation.
Examples
The following code example demonstrates methods to get the length of an array.

◆ long_length()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
virtual auto xtd::basic_array< type_t, allocator_t >::long_length ( ) -> xtd::int64
inlinenodiscardvirtual

Gets a 64-bit integer that represents the total number of elements in all the dimensions of the array.

Returns
int64 A 64-bit integer that represents the total number of elements in all the dimensions of the array; zero if there are no elements in the array.
Remarks
Retrieving the value of this property is an O(1) operation.

◆ max_length()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
virtual auto xtd::basic_array< type_t, allocator_t >::max_length ( ) const -> size_type
inlinenodiscardvirtualnoexcept

Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(xtd::array::begin(), xtd::array::end()) for the largest container.

Returns
Maximum number of elements.

◆ rank()

◆ sync_root()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::sync_root ( ) const -> const xtd::object &
inlinenodiscardoverridenoexcept

Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.

Returns
An object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.
Remarks
For collections whose underlying store is not publicly available, the expected implementation is to return the current instance. Note that the pointer to the current instance might not be sufficient for collections that wrap other collections; those should return the underlying collection's sync_root property.
Most collection classes in the xts::.collections namespace also implement a synchronized method, which provides a synchronized wrapper around the underlying collection. However, derived classes can provide their own synchronized version of the collection using the xtd::collections::generic::icollection::sync_root property. The synchronizing code must perform operations on the xtd::collections::generic::icollection::sync_root property of the collection, not directly on the collection. This ensures proper operation of collections that are derived from other objects. Specifically, it maintains proper synchronization with other threads that might be simultaneously modifying the collection instance.
In the absence of a synchronized method on a collection, the expected usage for the xtd::collections::generic::icollection::sync_root looks as follows:
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
// Some operation on the collection, which is now thread safe.
}
@encode
@remarks Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
@remarks The following code example shows how to lock the collection using the xtd::collections::generic::icollection::sync_root property during the entire enumeration.
@code
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
for (const auto& item : my_collection) {
// Insert your code here.
}
}
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.hpp:29
Definition enumeration.hpp:12
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:484
@ other
The operating system is other.
Definition platform_id.hpp:60
@ a
The A key.
Definition console_key.hpp:88

◆ contains()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::contains ( const type_t & value) const -> bool
inlinenodiscardoverridenoexcept

Determines whether an element is in the array.

Parameters
valueThe object to be added to the end of the array.

◆ copy_to() [1/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::copy_to ( xtd::array< type_t > & array) const -> void
inline

Copies the entire xtd::array <type_t> to a compatible one-dimensional array.

Parameters
arrayThe one-dimensional xtd::array that is the destination of the elements copied from ICollection. The xtd::array must have zero-based indexing.
Exceptions
xtd::argument_exceptionThe number of elements in the source xtd::array <type_t> is greater than the number of elements that the destination array can contain.

◆ copy_to() [2/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::copy_to ( xtd::array< type_t > & array,
size_type array_index ) const -> void
inlineoverride

Copies the elements of the xtd::array <type_t> to an xtd::array, starting at a particular xtd::array index.

Parameters
arrayThe one-dimensional xtd::array that is the destination of the elements copied from xtd::collections::generic::icollection <type_t>. The xtd::array must have zero-based indexing.
array_indexThe zero-based index in array at which copying begins.
Exceptions
xtd::argument_exceptionThe number of elements in the source xtd::array <type_t> is greater than the available space from `array_index` to the end of the destination `array`.

◆ equals()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::equals ( const object & obj) const -> bool
inlinenodiscardoverridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.
Examples
The following code example compares the current instance with another object.
#include <xtd/xtd>
auto main() -> int {
auto object1 = new_ptr<object>();
auto object2 = new_ptr<object>();
auto object3 = object2;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
object3 = object1;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
}
// This code produces the following output :
//
// false
// false
// true
// true
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24

Reimplemented from xtd::object.

◆ fill()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
virtual auto xtd::basic_array< type_t, allocator_t >::fill ( const value_type & value) -> void
inlinevirtualnoexcept

Assigns the value to all elements in the container.

Parameters
valueThe value to assign to the elements.

◆ get_length()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::get_length ( size_type dimension) const -> size_type
inlinenodiscardconstexpr

Gets the total number of elements in all the dimensions of the array.

Parameters
dimensionA zero-based dimension of the array whose length needs to be determined.
Returns
The total number of elements in all the dimensions of the array; zero if there are no elements in the array.
Exceptions
xtd::argument_out_of_range_exception`dimension` is equal to or greater than xtd::basic_array::rank.
Examples
The following code example demonstrates methods to get the length of an array.

◆ get_lengths()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::get_lengths ( ) const -> xtd::array< size_type, 1 >
nodiscard

Gets an array of the number of elements of all the dimensions of the array.

Returns
The array of the number of elements of all the dimensions of the array;

◆ get_long_length()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::get_long_length ( size_type dimension) const -> xtd::int64
inlinenodiscardconstexpr

Gets a 64-bit integer that represents the total number of elements in all the dimensions of the array.

Parameters
dimensionA zero-based dimension of the array whose length needs to be determined.
Returns
A 64-bit integer that represents the total number of elements in all the dimensions of the array; zero if there are no elements in the array.
Exceptions
xtd::argument_out_of_range_exception`dimension` is equal to or greater than xtd::basic_array::rank.
Examples
The following code example demonstrates methods to get the length of an array.

◆ get_lower_bound()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::get_lower_bound ( size_type dimension) const -> size_type
inlinenodiscardconstexpr

Gets the lower bound of the specified dimension in the array.

Parameters
dimensionA zero-based dimension of the array whose lower bound needs to be determined.
Returns
The lower bound of the specified dimension in the array.
Exceptions
xtd::argument_out_of_range_exception`dimension` is equal to or greater than xtd::basic_array::rank.
Examples
The following code example uses xtd::array::get_lower_bound and xtd::array::get_upper_bound to initialize a one-dimensional array and a multidimensional array.

◆ get_upper_bound()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::get_upper_bound ( size_type dimension) const -> size_type
inlinenodiscardconstexpr

Gets the upper bound of the specified dimension in the array.

Parameters
dimensionA zero-based dimension of the array whose upper bound needs to be determined.
Returns
The upper bound of the specified dimension in the array.
Exceptions
xtd::argument_out_of_range_exception`dimension` is equal to or greater than xtd::basic_array::rank.
Examples
The following code example uses xtd::array::get_lower_bound and xtd::array::get_upper_bound to initialize a one-dimensional array and a multidimensional array.

◆ get_value()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::get_value ( const xtd::array< size_type > & indexes) const -> const value_type &
nodiscard

Gets the value at the specified position in the multidimensional array. The indexes are specified as 32-bit integers array.

Parameters
indexesAn array that represents the position of the element to get.
Returns
The value at the specified position in the multidimensional array.
Exceptions
xtd::index_out_of_range_exceptionIf `indexes` is outside the range of valid indexes for the corresponding dimension of the current array.

◆ index_of()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::index_of ( const type_t & value) const -> size_type
inlinenodiscardoverridenoexcept

Determines the index of a specific item in the xtd::array <type_t>.

Parameters
valueThe object to locate in the xtd::array.
Returns
The index of value if found in the array; otherwise, xtd::collections::generic::ilist::npos.

◆ set_value()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::set_value ( const type_t & value,
const xtd::array< size_type > & indexes ) -> void
inline

Resizes the container to contain count elements, does nothing if count == length(). @param new_size The new size of the container. @exception xtd::argument_out_of_range_exception xtd::collections::generic::list::capacity is set to a value that is less than xtd::collections::generic::list::count. @remarks If the current size is greater than count, the container is reduced to its first count elements. @remarks If the current size is less than count`, additional default-inserted elements are appended. */ auto resize(size_type new_size) -> void {resize(new_size, value_type {});}.

/** Resizes the container to contain count elements, does nothing if count == length(). @param new_size The new size of the container. @param value The value to initialize the new elements with. @exception xtd::argument_out_of_range_exception xtd::collections::generic::list::capacity is set to a value that is less than xtd::collections::generic::list::count. @remarks If the current size is greater than count, the container is reduced to its first count elements. @remarks If the current size is less than count`, additional default-inserted elements are appended. */ auto resize(size_type new_size, value_type value) -> void { if (new_size == length()) return; if (rank() != 1) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument); if (new_size > max_length()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::out_of_memory); data_->items.resize(new_size, value); data_->upper_bound[0] = new_size - 1; }

/** Sets a value to the element at the specified position in the multidimensional array.

Parameters
valueThe new value for the specified element.
indexesAn array that represents the position of the element to set.
Exceptions
xtd::index_out_of_range_exceptionEither `indexes` is outside the range of valid indexes for the current array.

◆ sort() [1/4]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::sort ( ) -> basic_array< type_t > &
inline

Sorts the elements in the entire xtd::collections::generic::list <type_t> using the default comparer.

Exceptions
xtd::invalid_operation_exceptionThe default comparer xtd::collections::generic::comparer::default_comparer cannot find an implementation of the xtd::icomparable <type_t> generic interface.
Examples
The xtd::collections::generic::list::binary_search method overload is then used to search for two strings that are not in the list, and the xtd::collections::generic::list::insert method is used to insert them. The return value of the xtd::collections::generic::list::binary_search method is gretaer than xtd::collections::generic::list::count in each case, because the strings are not in the list. Taking the bitwise complement of this negative number produces the index of the first element in the list that is larger than the search string, and inserting at this location preserves the sort order. The second search string is larger than any element in the list, so the insertion position is at the end of the list.
#include <xtd/xtd>
class example {
public:
static auto main() -> void {
auto dinosaurs = list<string> {};
dinosaurs.add("Pachycephalosaurus");
dinosaurs.add("Amargasaurus");
dinosaurs.add("Mamenchisaurus");
dinosaurs.add("Deinonychus");
for (auto dinosaur : dinosaurs)
dinosaurs.sort();
for (auto dinosaur : dinosaurs)
console::write_line("\nbinary_search and insert \"Coelophysis\":");
auto index = dinosaurs.binary_search("Coelophysis");
if (index > dinosaurs.count()) dinosaurs.insert(~index, "Coelophysis");
for (string dinosaur : dinosaurs)
console::write_line("\nbinary_search and insert \"Tyrannosaurus\":");
index = dinosaurs.binary_search("Tyrannosaurus");
if (index > dinosaurs.count()) dinosaurs.insert(~index, "Tyrannosaurus");
for (auto dinosaur : dinosaurs)
}
};
startup_(example::main);
// This code produces the following output :
//
//
// Pachycephalosaurus
// Amargasaurus
// Mamenchisaurus
// Deinonychus
//
// sort
//
// Amargasaurus
// Deinonychus
// Mamenchisaurus
// Pachycephalosaurus
//
// binary_search and insert "Coelophysis":
//
// Amargasaurus
// Coelophysis
// Deinonychus
// Mamenchisaurus
// Pachycephalosaurus
//
// binary_search and insert "Tyrannosaurus":
//
// Amargasaurus
// Coelophysis
// Deinonychus
// Mamenchisaurus
// Pachycephalosaurus
// Tyrannosaurus
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:284
Remarks
This method uses the default comparer xtd::collections::generic::comparer::default_comparer for type type_t to determine the order of list elements. The xtd::collections::generic::comparer::default_comparer property checks whether type type_t implements the xtd::icomparable <type_t> generic interface and uses that implementation, if available. If not, xtd::collections::generic::comparer::default_comparer checks whether type T implements the xtd::icomparable interface. If type type_t does not implement either interface, xtd::collections::generic::comparer::default_comparer throws an xtd::invalid_operation_exception.
This method uses xtd::array::sort, which uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two elements are equal, their order might ! be preserved. In contrast, a stable sort preserves the order of elements that are equal.
On average, this method is an O(n log n) operation, where n is xtd::collections::generic::list::count; in the worst case it is an O(n ^ 2) operation.
The following code example demonstrates the xtd::collections::generic::list::sort method overload and the xtd::collections::generic::list::binary_search method overload. A xtd::collections::generic::list <type_t> of strings is created and populated with four strings, in no particular order. The list is displayed, sorted, and displayed again.

◆ sort() [2/4]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
template<typename comparison_t>
auto xtd::basic_array< type_t, allocator_t >::sort ( comparison_t && comparison) -> basic_array< type_t > &
inline

Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified xtd::comparison <type_t>.

Exceptions
xtd::argument_exceptionThe implementation of comparison caused an error during the sort. For example, comparison might not return 0 when comparing an item with itself.
Remarks
If comparison is provided, the elements of the xtd::collections::generic::list <type_t> are sorted using the method represented by the delegate.
This method uses xtd::array::sort, which uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two elements are equal, their order might ! be preserved. In contrast, a stable sort preserves the order of elements that are equal.
On average, this method is an O(n log n) operation, where n is xtd::collections::generic::list::count; in the worst case it is an O(n ^ 2) operation.

◆ sort() [3/4]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::sort ( const xtd::collections::generic::icomparer< type_t > & comparer) -> basic_array< type_t > &
inline

Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified comparer.

Parameters
comparerThe xtd::collections::generic::icomparer <type_t> implementation to use when comparing elements, or null to use the default comparer xtd::collections::generic::comparer::default_comparer.
Exceptions
xtd::argument_exceptionThe implementation of comparison caused an error during the sort. For example, comparison might not return 0 when comparing an item with itself.
Remarks
If comparer is provided, the elements of the xtd::collections::generic::list <type_t> are sorted using the specified xtd::collections::generic::icomparer <type_t> implementation.
This method uses xtd::array::sort, which uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two elements are equal, their order might ! be preserved. In contrast, a stable sort preserves the order of elements that are equal.
On average, this method is an O(n log n) operation, where n is xtd::collections::generic::list::count; in the worst case it is an O(n ^ 2) operation.

◆ sort() [4/4]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::sort ( xtd::size index,
xtd::size count,
const xtd::collections::generic::icomparer< type_t > & comparer ) -> basic_array< type_t > &
inline

Sorts the elements in a range of elements in xtd::collections::generic::list <type_t> using the specified comparer.

Parameters
indexThe zero-based starting index of the range to sort.
countThe length of the range to sort.
comparerThe xtd::collections::generic::icomparer <type_t> implementation to use when comparing elements, or null to use the default comparer xtd::collections::generic::comparer::default_comparer.
Exceptions
xtd::argument_exceptionThe implementation of comparison caused an error during the sort. For example, comparison might not return 0 when comparing an item with itself.
Remarks
If comparer is provided, the elements of the xtd::collections::generic::list <type_t> are sorted using the specified xtd::collections::generic::icomparer <type_t> implementation.
This method uses xtd::array::sort, which uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two elements are equal, their order might ! be preserved. In contrast, a stable sort preserves the order of elements that are equal.
On average, this method is an O(n log n) operation, where n is xtd::collections::generic::list::count; in the worst case it is an O(n ^ 2) operation.

◆ to_string()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::to_string ( ) const -> xtd::string
nodiscardoverridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

◆ operator=() [1/3]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::operator= ( const basic_array< type_t, allocator_t > & other) -> basic_array &
inline

Copy assignment operator. Replaces the contents with a copy of the contents of other.

Parameters
otherAnother container to use as data source.
Returns
This current instance.

◆ operator=() [2/3]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::operator= ( basic_array< type_t, allocator_t > && other) -> basic_array &=default
defaultnoexcept

Move assignment operator. Replaces the contents with those of other using move semantics (i.e. the data in other is moved from other into this container). other is in a valid but unspecified state afterwards.

Parameters
otherAnother base type container to use as data source.
Returns
This current instance.

◆ operator=() [3/3]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::operator= ( std::initializer_list< type_t > & items) -> basic_array &
inline

Replaces the contents with those identified by initializer list ilist.

Parameters
itemsInitializer list to use as data source
Returns
This current instance.

◆ operator[]() [1/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::operator[] ( size_type index) const -> const_reference
inlinenodiscardoverride

Returns a reference to the element at specified location index.

Parameters
indexThe position of the element to return.
Returns
Reference to the requested element.
Exceptions
xtd::index_out_of_range_exceptionIf pos is not within the range of the container.

◆ operator[]() [2/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::operator[] ( size_type index) -> reference
inlinenodiscardoverride

Returns a reference to the element at specified location index.

Parameters
indexThe position of the element to return.
Returns
Reference to the requested element.
Exceptions
xtd::index_out_of_range_exceptionIf `index` is not within the range of the container.

◆ operator const base_type &()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
xtd::basic_array< type_t, allocator_t >::operator const base_type & ( ) const
inlinenodiscardnoexcept

Returns a reference to the underlying base type.

Returns
Reference to the underlying base type.

◆ operator base_type &()

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
xtd::basic_array< type_t, allocator_t >::operator base_type & ( )
inlinenodiscardnoexcept

Returns a reference to the underlying base type.

Returns
Reference to the underlying base type.

◆ operator()() [1/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::operator() ( const xtd::array< size_type > & indexes) -> type_t &
nodiscard

Gets the value at the specified position in the multidimensional array. The indexes are specified as a 32-bit integer array.

Parameters
indexesAn array that represents the multidimension index of the array element to get.
Returns
The value at the specified position in the multidimensional array.
Exceptions
xtd::index_out_of_range_exceptionEither each index is outside the range of valid indexes for the corresponding dimension of the current array.
Examples
The following code example shows how to use operator [] to list the elements of an array.

◆ operator()() [2/2]

template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
auto xtd::basic_array< type_t, allocator_t >::operator() ( const xtd::array< size_type > & indexes) const -> const type_t &
nodiscard

Gets the value at the specified position in the multidimensional array. The indexes are specified as a 32-bit integer array.

Parameters
indexesAn array that represents the multidimension index of the array element to get.
Returns
The value at the specified position in the multidimensional array.
Exceptions
xtd::index_out_of_range_exceptionEither each index is outside the range of valid indexes for the corresponding dimension of the current array.
Examples
The following code example shows how to use operator [] to list the elements of an array.

The documentation for this class was generated from the following file: