xtd 0.2.0
Loading...
Searching...
No Matches
xtd::array<> Class Reference
Inheritance diagram for xtd::array<>:
xtd::basic_array< type_t, allocator_t > xtd::static_object xtd::array_abstract_object xtd::iequatable< basic_array< type_t, allocator_t > > xtd::abstract_object xtd::interface xtd::extensions::equality_operators< type_t, iequatable< type_t > > xtd::object

Definition

Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays.

Definition
template<class type_t, xtd::size rank_, class allocator_t>
class array : public xtd::basic_array<type_t, allocator_t>;
array()=default
Base object that represent array.
Definition basic_array.hpp:27
Header
#include <xtd/array>
Namespace
xtd
Library
xtd.core
Remarks
The xtd::array class is not part of the xtd::collections namespaces. However, it is still considered a collection because it is based on the xtd::collections::generic::ilist interface.
An element is a value in an xtd::array. The length of an xtd::array is the total number of elements it can contain. The lower bound of an v is the index of its first element. An xtd::array can have any lower bound, but it has a lower bound of zero by default. A different lower bound can be defined when creating an instance of the xtd::array class using xtd::array::create_instance. A multidimensional xtd::array can have different bounds for each dimension. An array can have a maximum of 32 dimensions.
Unlike the classes in the xtd::collections namespaces, xtd::array has a fixed capacity. To increase the capacity, you must create a new xtd::array object with the required capacity, copy the elements from the old xtd::array object to the new one, and delete the old xtd::array.
The xtd::array class implements the xtd::collections::generic::ilist, xtd::collections::generic::icollection, and xtd::collections::generic::ienumerable generic interfaces. The implementations are provided to arrays at run time, and as a result, the generic interfaces do not appear in the declaration syntax for the xtd::array class. In addition, there are no reference topics for interface members that are accessible only by casting an array to the generic interface type (explicit interface implementations). The key thing to be aware of when you cast an array to one of these interfaces is that members which add, insert, or remove elements throw xtd::not_supported_exception.
The xtd::array::copy method copies elements not only between arrays of the same type but also between standard arrays of different types; it handles type casting automatically.
Some methods, such as xtd::array::create_instance, xtd::array::copy, xtd::array::copy_to, xtd::array::get_value, and xtd::array::set_value, provide overloads that accept 64-bit integers as parameters to accommodate large capacity arrays. xtd::array::long_length and xtd::array::get_long_length return 64-bit integers indicating the length of the array.
The xtd::array is not guaranteed to be sorted. You must sort the xtd::array prior to performing operations (such as xtd::array::binary_search) that require the xtd::array to be sorted.
Examples
The following code example demonstrates different methods to create an array.
Examples
The following code example creates and initializes an array and displays its properties and its elements.
#include <xtd/xtd>
auto print_values(const array<int>& my_arr) {
for (auto i : my_arr)
console::write("\t{}", i);
}
auto print_values(const array<any_object>& my_arr) {
for (auto o : my_arr)
console::write("\t{}", o);
}
auto main() -> int {
// Creates and initializes a new integer array and a new Object array.
auto my_int_array = array<int> {1, 2, 3, 4, 5};
auto my_obj_array = array<any_object> {26, 27, 28, 29, 30};
// Prints the initial values of both arrays.
console::write_line("Initially,");
console::write("integer array:");
print_values(my_int_array);
console::write("Object array: ");
print_values(my_obj_array);
// Copies the first two elements from the integer array to the Object array.
array<>::copy(my_int_array, my_obj_array, 2);
// Prints the values of the modified arrays.
console::write_line("\nAfter copying the first two elements of the integer array to the Object array,");
console::write("integer array:");
print_values(my_int_array);
console::write("Object array: ");
print_values(my_obj_array);
// Copies the last two elements from the object array to the integer array.
xtd::array<>::copy(my_obj_array, my_obj_array.get_upper_bound(0) - 1, my_int_array, my_int_array.get_upper_bound(0) - 1, 2);
// Prints the values of the modified arrays.
console::write_line("\nAfter copying the last two elements of the Object array to the integer array,");
console::write("integer array:");
print_values(my_int_array);
console::write("Object array: ");
print_values(my_obj_array);
}
// This code produces the following output :
//
// Initially,
// integer array: 1 2 3 4 5
// Object array: 26 27 28 29 30
//
// After copying the first two elements of the integer array to the Object array,
// integer array: 1 2 3 4 5
// Object array: 1 2 28 29 30
//
// After copying the last two elements of the Object array to the integer array,
// integer array: 1 2 3 29 30
// Object array: 1 2 28 29 30
static void copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array)
Copies a range of elements from an xtd::array starting at the first element and pastes them into anot...
Definition array_static.hpp:239
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:462
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
@ i
The I key.
Definition console_key.hpp:104
@ o
The O key.
Definition console_key.hpp:116

Public Static Methods

template<class type_t, class allocator_t>
static xtd::collections::object_model::read_only_collection< type_t > as_read_only (const xtd::array< type_t, 1, allocator_t > &array)
 Returns a read-only wrapper for the specified array.
 
template<class type_t, class allocator_t>
static int32 binary_search (const array< type_t, 1, allocator_t > &array, int32 index, int32 length, const type_t &value)
 Searches a range of elements in a one-dimensional sorted array for a value, using the xtd::icomparable interface implemented by each element of the array and by the specified value.
 
template<class type_t, class allocator_t>
static xtd::size binary_search (const array< type_t, 1, allocator_t > &array, xtd::size index, xtd::size count, const type_t &value, const xtd::collections::generic::icomparer< type_t > &comparer)
 Searches a range of elements in a one-dimensional sorted array for a value, using the specified xtd::icomparer interface.
 
template<class type_t, class allocator_t>
static xtd::size binary_search (const array< type_t, 1, allocator_t > &array, const type_t &value)
 Searches an entire one-dimensional sorted array for a specific element, using the xtd::icomparable interface implemented by each element of the array and by the specified object.
 
template<class type_t, class allocator_t>
static xtd::size binary_search (const array< type_t, 1, allocator_t > &array, const type_t &value, const xtd::collections::generic::icomparer< type_t > &comparer)
 Searches a range of elements in a one-dimensional sorted array for a value, using the specified xtd::icomparer interface.
 
template<class type_t, xtd::size rank, class allocator_t>
static void clear (const array< type_t, rank, allocator_t > &array)
 Clears the contents of an array.
 
template<class type_t, xtd::size rank, class allocator_t>
static void clear (const array< type_t, rank, allocator_t > &array, xtd::size index, xtd::size length)
 Sets a range of elements in an array to the default value of each element type.
 
template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void constrained_copy (const array< source_type_t, source_rank, source_allocator_t > &source_array, const xtd::array< xtd::size > &source_indexes, array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, const xtd::array< xtd::size > &destination_indexes, xtd::size length)
 Copies a range of elements from an xtd::array starting at the specified source index and pastes them to another xtd::array starting at the specified destination index. Guarantees that all changes are undone if the copy does not succeed completely.
 
template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void constrained_copy (const array< source_type_t, source_rank, source_allocator_t > &source_array, xtd::size source_index, array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::size destination_index, xtd::size length)
 Copies a range of elements from an xtd::array starting at the specified source index and pastes them to another xtd::array starting at the specified destination index. Guarantees that all changes are undone if the copy does not succeed completely.
 
template<class output_t, class input_t, xtd::size rank, class allocator_t, class converter_t, class destination_allocator_t = xtd::collections::generic::helpers::allocator<output_t>>
static xtd::array< output_t, rank, destination_allocator_t > convert_all (const xtd::array< input_t, rank, allocator_t > &array, converter_t converter)
 Converts an array of one type to an array of another type.
 
template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void copy (const array< source_type_t, source_rank, source_allocator_t > &source_array, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array)
 Copies a range of elements from an xtd::array starting at the first element and pastes them into another xtd::array starting at the first element. The length is specified as an xtd::size.
 
template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void copy (const array< source_type_t, source_rank, source_allocator_t > &source_array, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::size length)
 Copies a range of elements from an xtd::array starting at the first element and pastes them into another xtd::array starting at the first element. The length is specified as an xtd::size.
 
template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void copy (const array< source_type_t, source_rank, source_allocator_t > &source_array, const xtd::array< xtd::size > &source_indexes, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, const xtd::array< xtd::size > &destination_indexes, xtd::size length)
 Copies a range of elements from an xtd::array starting at the specified source index and pastes them to another xtd::array starting at the specified destination index. The length and the indexes are specified as 64-bit integers.
 
template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void copy (const array< source_type_t, source_rank, source_allocator_t > &source_array, xtd::size source_index, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::size destination_index, xtd::size length)
 Copies a range of elements from an xtd::array starting at the specified source index and pastes them to another xtd::array starting at the specified destination index. The length and the indexes are specified as 64-bit integers.
 
template<class type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::array< type_t, 1, allocator_t > create_instance (xtd::size length)
 Creates a one-dimensional xtd::array <type_t> of the specified Type and length, with zero-based indexing.
 
template<class type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::array< type_t, 2, allocator_t > create_instance (xtd::size length1, xtd::size length2)
 Creates a two-dimensional xtd::array <type_t> of the specified Type and dimension lengths, with zero-based indexing.
 
template<typename type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::array< type_t, 3, allocator_t > create_instance (xtd::size length1, xtd::size length2, xtd::size length3)
 Creates a three-dimensional xtd::array <type_t> of the specified Type and dimension lengths, with zero-based indexing.
 
template<class type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::array< type_t, rank, allocator_t > create_instance (const xtd::array< xtd::size > &lengths)
 Creates a multidimensional xtd::array <type_t> of the specified Type and dimension lengths, with zero-based indexing. The dimension lengths are specified in an array of 32-bit integers.
 
template<class type_t, xtd::size rank, class allocator_t, class predicate_t>
static bool exists (const xtd::array< type_t, rank, allocator_t > &array, predicate_t match)
 Determines whether the xtd::array <type_t> contains elements that match the conditions defined by the specified predicate..
 
template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::size index_of (const xtd::array< type_t, rank, allocator_t > &array, const type_t &value) noexcept
 Determines the index of a specific item in the array specified.
 
template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::size index_of (const xtd::array< type_t, rank, allocator_t > &array, const type_t &value, xtd::size index)
 Determines the index of a specific item in the array specified.
 
template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::size index_of (const xtd::array< type_t, rank, allocator_t > &array, const type_t &value, xtd::size index, xtd::size count)
 Determines the index of a specific item in the array specified.
 
template<class type_t, class allocator_t>
static void resize (xtd::array< type_t, 1, allocator_t > &array, int32 new_size)
 Changes the number of elements of a one-dimensional array to the specified new size.
 
template<class type_t, class allocator_t>
static void reverse (xtd::array< type_t, 1, allocator_t > &array)
 Reverses the order of the elements in the entire xtd::basic_array.
 
template<class type_t, class allocator_t>
static void reverse (xtd::array< type_t, 1, allocator_t > &array, int32 index, int32 count)
 Reverses the order of the elements in the specified range.
 

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 Constructors

 array ()=default
 Initializes a new instance of the array class that is empty.
 
 array (const array &array)
 Copy constructor with specified array.
 
 array (array &&array)=default
 Move constructor with specified array.
 
 array (const array< xtd::size, 1 > &lengths)
 Initializes a new instance of the array class with lengths for each rank specified.
 
 array (const array< xtd::size, 1 > &lengths, const type_t &value)
 Initializes a new instance of the array class with lengths for each rank specified.
 

Public Properties

xtd::size rank () const noexcept override
 Gets the rank (number of dimensions) of the array.
 

Public Methods

xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
 

Public Operators

arrayoperator= (const array &)=default
 Copy assignment operator. Replaces the contents with a copy of the contents of other.
 
arrayoperator= (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.
 

Additional Inherited Members

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.
 
size_type count () const noexcept override
 Gets the number of elements contained in the xtd::array <type_t>.
 
virtual pointer data () noexcept
 Returns pointer to the underlying array serving as element storage.
 
virtual const_pointer data () const noexcept
 Returns pointer to the underlying array serving as element storage.
 
bool is_fixed_size () const noexcept override
 Gets a value indicating whether the xtd::collections::generic::ilist <type_t> has a fixed size.
 
bool is_read_only () const noexcept override
 Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
 
bool is_synchronized () const noexcept override
 Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe).
 
virtual const base_typeitems () const noexcept
 Returns the underlying base type items.
 
virtual base_typeitems () noexcept
 Returns the underlying base type items.
 
virtual size_type length () const noexcept
 Gets a size that represents the total number of elements in all the dimensions of the array.
 
virtual xtd::int64 long_length ()
 Gets a 64-bit integer that represents the total number of elements in all the dimensions of the array.
 
virtual size_type max_length () const noexcept
 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.
 
const xtd::objectsync_root () const noexcept override
 Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.
 
bool contains (const type_t &value) const noexcept override
 Determines whether an element is in the array.
 
void copy_to (xtd::array< type_t > &array) const
 
void copy_to (xtd::array< type_t > &array, size_type array_index) const override
 Copies the elements of the xtd::array <type_t> to an xtd::array, starting at a particular xtd::array index.
 
void copy_to (const xtd::array< size_type > &indexes, xtd::array< type_t > &array, size_type array_index) const
 
void copy_to (const xtd::array< size_type > &indexes, xtd::array< type_t > &array, size_type array_index, size_type count) const
 
void copy_to (const size_type index, xtd::array< type_t > &array, size_type array_index) const
 
void copy_to (const size_type index, xtd::array< type_t > &array, size_type array_index, size_type count) const
 
bool equals (const object &obj) const noexcept override
 Determines whether the specified object is equal to the current object.
 
bool equals (const basic_array &rhs) const noexcept override
 
virtual void fill (const value_type &value) noexcept
 Assigns the value to all elements in the container.
 
xtd::collections::generic::enumerator< value_typeget_enumerator () const noexcept override
 
constexpr size_type get_length (size_type dimension) const
 Gets the total number of elements in all the dimensions of the array.
 
xtd::array< size_type, 1 > get_lengths () const
 Gets an array of the number of elements of all the dimensions of the array.
 
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.
 
constexpr size_type get_lower_bound (size_type dimension) const
 Gets the lower bound of the specified dimension in the array.
 
constexpr size_type get_upper_bound (size_type dimension) const
 Gets the upper bound of the specified dimension in the array.
 
const value_typeget_value (const xtd::array< size_type > &indexes) const
 Gets the value at the specified position in the multidimensional array. The indexes are specified as 32-bit integers array.
 
size_type index_of (const type_t &value) const noexcept override
 Determines the index of a specific item in the xtd::array <type_t>.
 
size_type index_of (const type_t &value, size_type index) const
 
size_type index_of (const type_t &value, size_type index, size_type count) const
 
void resize (size_type new_size, value_type value)
 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 thancount, the container is reduced to its firstcountelements. / @remarks If the current size is less thancount`, additional default-inserted elements are appended. void resize(size_type new_size) {resize(new_size, value_type {});}.
 
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.
 
basic_array< type_t > & sort ()
 Sorts the elements in the entire xtd::collections::generic::list <type_t> using the default comparer.
 
basic_array< type_t > & sort (comparison_t &&comparison)
 Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified xtd::comparison <type_t>.
 
basic_array< type_t > & sort (const xtd::collections::generic::icomparer< type_t > &comparer)
 Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified comparer.
 
basic_array< type_t > & sort (xtd::size index, xtd::size count, const xtd::collections::generic::icomparer< type_t > &comparer)
 Sorts the elements in a range of elements in xtd::collections::generic::list <type_t> using the specified comparer.
 
xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
 
basic_arrayoperator= (const basic_array &other)
 Copy assignment operator. Replaces the contents with a copy of the contents of other.
 
basic_arrayoperator= (basic_array &&other) noexcept=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.
 
basic_arrayoperator= (std::initializer_list< type_t > &items)
 Replaces the contents with those identified by initializer list ilist.
 
const_reference operator[] (size_type index) const override
 Returns a reference to the element at specified location index.
 
reference operator[] (size_type index) 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.
 
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 a 32-bit integer array.
 
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 a 32-bit integer array.
 
 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<class 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<class object_a_t, class 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<class object_a_t, class 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

using xtd::array< type_t, rank_, allocator_t >::value_type

Represents the array value type.

◆ allocator_type

using xtd::array< type_t, rank_, allocator_t >::allocator_type

Represents the array allocator type.

◆ base_type

using xtd::array< type_t, rank_, allocator_t >::base_type

Represents the array base type.

◆ size_type

using xtd::array< type_t, rank_, allocator_t >::size_type

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

◆ difference_type

using xtd::array< type_t, rank_, allocator_t >::difference_type

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

◆ reference

using xtd::array< type_t, rank_, allocator_t >::reference

Represents the reference of array value type.

◆ const_reference

using xtd::array< type_t, rank_, allocator_t >::const_reference

Represents the const reference of array value type.

◆ pointer

using xtd::array< type_t, rank_, allocator_t >::pointer

Represents the pointer of array value type.

◆ const_pointer

using xtd::array< type_t, rank_, allocator_t >::const_pointer

Represents the const pointer of array value type.

◆ iterator

using xtd::array< type_t, rank_, allocator_t >::iterator

Represents the iterator of array value type.

◆ const_iterator

using xtd::array< type_t, rank_, allocator_t >::const_iterator

Represents the const iterator of array value type.

◆ reverse_iterator

using xtd::array< type_t, rank_, allocator_t >::reverse_iterator

Represents the reverse iterator of array value type.

◆ const_reverse_iterator

using xtd::array< type_t, rank_, allocator_t >::const_reverse_iterator

Represents the const reverse iterator of array value type.

Constructor & Destructor Documentation

◆ array() [1/5]

xtd::array< type_t, rank_, allocator_t >::array ( )
default

Initializes a new instance of the array class that is empty.

Remarks
The array class is not thread safe.
Examples
The following code example demonstrates different methods to create an array.

◆ array() [2/5]

xtd::array< type_t, rank_, allocator_t >::array ( const array<> & array)
inline

Copy constructor with specified array.

Parameters
arrayThe xtd::array which elements will be inserted from.

◆ array() [3/5]

xtd::array< type_t, rank_, allocator_t >::array ( array<> && array)
default

Move constructor with specified array.

Parameters
arrayThe xtd::array which elements will be inserted from.

◆ array() [4/5]

xtd::array< type_t, rank_, allocator_t >::array ( const array< xtd::size, 1 > & lengths)
inline

Initializes a new instance of the array class with lengths for each rank specified.

Parameters
lengthsthe lengths for each rank.
Remarks
The array class is not thread safe.
Examples
The following code example demonstrates different methods to create an array.

◆ array() [5/5]

xtd::array< type_t, rank_, allocator_t >::array ( const array< xtd::size, 1 > & lengths,
const type_t & value )
inline

Initializes a new instance of the array class with lengths for each rank specified.

Parameters
lengthsthe lengths for each rank.
Remarks
The array class is not thread safe.
Examples
The following code example demonstrates different methods to create an array.

Member Function Documentation

◆ as_read_only()

template<class type_t, class allocator_t>
static xtd::collections::object_model::read_only_collection< type_t > xtd::array<>::as_read_only ( const xtd::array< type_t, 1, allocator_t > & array)
inlinestatic

Returns a read-only wrapper for the specified array.

Parameters
arrayThe one-dimensional, zero-based array to wrap in a read-only xtd::collections::object_model::read_only_collection<type_t> wrapper.
Returns
A read-only xtd::collections::object_model::read_only_collection<type_t> wrapper for the specified array.
Remarks
To prevent any modifications to the array, expose the array only through this wrapper.
A collection that is read-only is simply a collection with a wrapper that prevents modifying the collection; therefore, if changes are made to the underlying collection, the read-only collection reflects those changes.
This method is an O(n) operation.
Examples
The following example wraps an array in a read-only xtd::collections::object_model::read_only_collection<type_t>.
#include <xtd/xtd>
auto print_index_and_values(const array<string>& my_arr) {
for (auto i = 0_z; i < my_arr.length(); ++i)
console::write_line(" [{0}] : {1}", i, my_arr[i]);
}
auto print_index_and_values(const ilist<string>& my_list) {
for (auto i = 0_z; i < my_list.count(); ++i)
console::write_line( " [{0}] : {1}", i, my_list[i]);
}
auto main() -> int {
// Create and initialize a new string array.
auto my_arr = array<string> {"The", "quick", "brown", "fox"};
// Display the values of the array.
console::write_line("The string array initially contains the following values:");
print_index_and_values(my_arr);
// Create a read-only ilist wrapper around the array.
auto my_list = array<>::as_read_only(my_arr);
// Display the values of the read-only ilist.
console::write_line("The read-only ilist contains the following values:");
print_index_and_values(my_list);
// Attempt to change a value through the wrapper.
try {
my_list[3] = "CAT";
} catch (const not_supported_exception& e) {
console::write_line("{} - {}", e.get_type(), e.message());
console::write_line();
}
// Change a value in the original array.
my_arr[2] = "RED";
// Display the values of the array.
console::write_line("After changing the third element, the string array contains the following values:");
print_index_and_values( my_arr );
// Display the values of the read-only ilist.
console::write_line("After changing the third element, the read-only ilist contains the following values:");
print_index_and_values(my_list);
}
// This code produces the following output :
//
// The string array initially contains the following values:
// [0] : The
// [1] : quick
// [2] : brown
// [3] : fox
//
// The read-only ilist contains the following values:
// [0] : The
// [1] : quick
// [2] : brown
// [3] : fox
//
// xtd::not_supported_exception - Collection is read-only.
//
// After changing the third element, the string array contains the following values:
// [0] : The
// [1] : quick
// [2] : RED
// [3] : fox
//
// After changing the third element, the read-only ilist contains the following values:
// [0] : The
// [1] : quick
// [2] : RED
// [3] : fox
//
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.hpp:124
@ e
The E key.
Definition console_key.hpp:96

◆ binary_search() [1/4]

template<class type_t, class allocator_t>
static int32 xtd::array<>::binary_search ( const array< type_t, 1, allocator_t > & array,
int32 index,
int32 length,
const type_t & value )
inlinestatic

Searches a range of elements in a one-dimensional sorted array for a value, using the xtd::icomparable interface implemented by each element of the array and by the specified value.

Parameters
arrayThe sorted one-dimensional array to search.
indexThe starting index of the range to search.
lengthThe length of the range to search.
valueThe object to search for.
Returns
int32 The index of the specified value in the specified array, if value is found; otherwise, a negative number. If value is not found and value is less than one or more elements in array, the negative number returned is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than all elements in array, the negative number returned is the bitwise complement of (the index of the last element plus 1). If this method is called with a non-sorted array, the return value can be incorrect and a negative number could be returned, even if value is present in array.
Exceptions
xtd::rank_exceptionarray is multidimensional.
xtd::argument_out_of_range_exceptionindex is less than the lower bound of array.
-or-<bre> length is less than zero.
xtd::argument_exceptionindex and length do not specify a valid range in array.
-or-<bre> value is of a type that is not compatible with the elements of array.
xtd::invalid_operation_exceptionvalue does not implement the xtd::icomparable interface, and the search encounters an element that does not implement the xtd::icomparable interface.
Remarks
This method does not support searching arrays that contain negative indexes. array must be sorted before calling this method.
If the array does not contain the specified value, the method returns a negative integer. You can apply the bitwise complement operator ~ to the negative result to produce an index. If this index is one greater than the upper bound of the array, there are no elements larger than value in the array. Otherwise, it is the index of the first element that is larger than value.
Either value or every element of array must implement the xtd::icomparable interface, which is used for comparisons. The elements of array must already be sorted in increasing value according to the sort order defined by the xtd::icomparable implementation; otherwise, the result might be incorrect.
Note
If value does not implement the xtd::icomparable interface, the elements of array are not tested for xtd::icomparable before the search begins. An exception is thrown if the search encounters an element that does not implement xtd::icomparable.
Remarks
Duplicate elements are allowed. If the array contains more than one element equal to value, the method returns the index of only one of the occurrences, and not necessarily the first one.
null can always be compared with any other reference type; therefore, comparisons with null do not generate an exception.
Note
For every element tested, value is passed to the appropriate xtd::icomparable implementation, even if value is null. That is, the xtd::icomparable implementation determines how a given element compares to null.
Remarks
This method is an O(log n) operation, where n is length.

◆ binary_search() [2/4]

template<class type_t, class allocator_t>
static xtd::size xtd::array<>::binary_search ( const array< type_t, 1, allocator_t > & array,
xtd::size index,
xtd::size count,
const type_t & value,
const xtd::collections::generic::icomparer< type_t > & comparer )
inlinestatic

Searches a range of elements in a one-dimensional sorted array for a value, using the specified xtd::icomparer interface.

Parameters
arrayThe sorted one-dimensional array to search.
indexThe starting index of the range to search.
lengthThe length of the range to search.
valueThe object to search for.
comparerThe xtd::icomparer implementation to use when comparing elements.
-or-<bre> null to use the xtd::icomparable implementation of each element.
Returns
int32 The index of the specified value in the specified array, if value is found; otherwise, a negative number. If value is not found and value is less than one or more elements in array, the negative number returned is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than all elements in array, the negative number returned is the bitwise complement of (the index of the last element plus 1). If this method is called with a non-sorted array, the return value can be incorrect and a negative number could be returned, even if value is present in array.
Exceptions
xtd::rank_exceptionarray is multidimensional.
xtd::argument_out_of_range_exceptionindex is less than the lower bound of array.
-or-<bre> length is less than zero.
xtd::argument_exceptionindex and length do not specify a valid range in array.
-or-<bre> value is of a type that is not compatible with the elements of array.
xtd::invalid_operation_exceptionvalue does not implement the xtd::icomparable interface, and the search encounters an element that does not implement the xtd::icomparable interface.
Remarks
This method does not support searching arrays that contain negative indexes. array must be sorted before calling this method.
If the array does not contain the specified value, the method returns a negative integer. You can apply the bitwise complement operator ~ to the negative result to produce an index. If this index is one greater than the upper bound of the array, there are no elements larger than value in the array. Otherwise, it is the index of the first element that is larger than value.
The comparer customizes how the elements are compared. For example, you can use a xtd::collections::case_insensitive_comparer as the comparer to perform case-insensitive string searches.
If comparer is not null, the elements of array are compared to the specified value using the specified xtd::icomparer implementation. The elements of array must already be sorted in increasing value according to the sort order defined by comparer; otherwise, the result might be incorrect.
If comparer is null, the comparison is done using the xtd::icomparable implementation provided by the element itself or by the specified value. The elements of array must already be sorted in increasing value according to the sort order defined by the xtd::icomparable implementation; otherwise, the result might be incorrect.
Note
If comparer is null and value does not implement the xtd::icomparable interface, the elements of array are not tested for xtd::icomparable before the search begins. An exception is thrown if the search encounters an element that does not implement xtd::icomparable.
Remarks
Duplicate elements are allowed. If the array contains more than one element equal to value, the method returns the index of only one of the occurrences, and not necessarily the first one.
null can always be compared with any other reference type; therefore, comparisons with null do not generate an exception when using xtd::icomparable.
Note
For every element tested, value is passed to the appropriate xtd::icomparable implementation, even if value is null. That is, the xtd::icomparable implementation determines how a given element compares to null.
Remarks
This method is an O(log n) operation, where n is length.

◆ binary_search() [3/4]

template<class type_t, class allocator_t>
static xtd::size xtd::array<>::binary_search ( const array< type_t, 1, allocator_t > & array,
const type_t & value )
inlinestatic

Searches an entire one-dimensional sorted array for a specific element, using the xtd::icomparable interface implemented by each element of the array and by the specified object.

Parameters
arrayThe sorted one-dimensional array to search.
valueThe object to search for.
Returns
int32 The index of the specified value in the specified array, if value is found; otherwise, a negative number. If value is not found and value is less than one or more elements in array, the negative number returned is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than all elements in array, the negative number returned is the bitwise complement of (the index of the last element plus 1). If this method is called with a non-sorted array, the return value can be incorrect and a negative number could be returned, even if value is present in array.
Exceptions
xtd::rank_exceptionarray is multidimensional.
xtd::argument_exceptionvalue is of a type that is not compatible with the elements of array.
xtd::invalid_operation_exceptionvalue does not implement the xtd::icomparable interface, and the search encounters an element that does not implement the xtd::icomparable interface.
Remarks
This method does not support searching arrays that contain negative indexes. array must be sorted before calling this method.
If the array does not contain the specified value, the method returns a negative integer. You can apply the bitwise complement operator ~ to the negative result to produce an index. If this index is one greater than the upper bound of the array, there are no elements larger than value in the array. Otherwise, it is the index of the first element that is larger than value.
Either value or every element of array must implement the xtd::icomparable interface, which is used for comparisons. The elements of array must already be sorted in increasing value according to the sort order defined by the xtd::icomparable implementation; otherwise, the result might be incorrect.
Note
Ifvalue does not implement the xtd::icomparable interface, the elements of array are not tested for xtd::icomparable before the search begins. An exception is thrown if the search encounters an element that does not implement xtd::icomparable.
Remarks
Duplicate elements are allowed. If the array contains more than one element equal to value, the method returns the index of only one of the occurrences, and not necessarily the first one.
null can always be compared with any other reference type; therefore, comparisons with null do not generate an exception.
Note
For every element tested, value is passed to the appropriate xtd::icomparable implementation, even if value is null. That is, the xtd::icomparable implementation determines how a given element compares to null.
Remarks
This method is an O(log n) operation, where n is the Length of array.

◆ binary_search() [4/4]

template<class type_t, class allocator_t>
static xtd::size xtd::array<>::binary_search ( const array< type_t, 1, allocator_t > & array,
const type_t & value,
const xtd::collections::generic::icomparer< type_t > & comparer )
inlinestatic

Searches a range of elements in a one-dimensional sorted array for a value, using the specified xtd::icomparer interface.

Parameters
arrayThe sorted one-dimensional array to search.
valueThe object to search for.
comparerThe xtd::icomparer implementation to use when comparing elements.
-or-<bre> null to use the xtd::icomparable implementation of each element.
Returns
int32 The index of the specified value in the specified array, if value is found; otherwise, a negative number. If value is not found and value is less than one or more elements in array, the negative number returned is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than all elements in array, the negative number returned is the bitwise complement of (the index of the last element plus 1). If this method is called with a non-sorted array, the return value can be incorrect and a negative number could be returned, even if value is present in array.
Exceptions
xtd::rank_exceptionarray is multidimensional.
xtd::argument_out_of_range_exceptionindex is less than the lower bound of array.
-or-<bre> length is less than zero.
xtd::argument_exceptionindex and length do not specify a valid range in array.
-or-<bre> value is of a type that is not compatible with the elements of array.
xtd::invalid_operation_exceptionvalue does not implement the xtd::icomparable interface, and the search encounters an element that does not implement the xtd::icomparable interface.
Remarks
This method does not support searching arrays that contain negative indexes. array must be sorted before calling this method.
If the array does not contain the specified value, the method returns a negative integer. You can apply the bitwise complement operator ~ to the negative result to produce an index. If this index is one greater than the upper bound of the array, there are no elements larger than value in the array. Otherwise, it is the index of the first element that is larger than value.
The comparer customizes how the elements are compared. For example, you can use a xtd::collections::case_insensitive_comparer as the comparer to perform case-insensitive string searches.
If comparer is not null, the elements of array are compared to the specified value using the specified xtd::icomparer implementation. The elements of array must already be sorted in increasing value according to the sort order defined by comparer; otherwise, the result might be incorrect.
If comparer is null, the comparison is done using the xtd::icomparable implementation provided by the element itself or by the specified value. The elements of array must already be sorted in increasing value according to the sort order defined by the xtd::icomparable implementation; otherwise, the result might be incorrect.
Note
If comparer is null and value does not implement the xtd::icomparable interface, the elements of array are not tested for xtd::icomparable before the search begins. An exception is thrown if the search encounters an element that does not implement xtd::icomparable.
Remarks
Duplicate elements are allowed. If the array contains more than one element equal to value, the method returns the index of only one of the occurrences, and not necessarily the first one.
null can always be compared with any other reference type; therefore, comparisons with null do not generate an exception when using xtd::icomparable.
Note
For every element tested, value is passed to the appropriate xtd::icomparable implementation, even if value is null. That is, the xtd::icomparable implementation determines how a given element compares to null.
Remarks
This method is an O(log n) operation, where n is length.

◆ clear() [1/2]

template<class type_t, xtd::size rank, class allocator_t>
static void xtd::array<>::clear ( const array< type_t, rank, allocator_t > & array)
inlinestatic

Clears the contents of an array.

Parameters
arrayThe array to clear.

◆ clear() [2/2]

template<class type_t, xtd::size rank, class allocator_t>
static void xtd::array<>::clear ( const array< type_t, rank, allocator_t > & array,
xtd::size index,
xtd::size length )
inlinestatic

Sets a range of elements in an array to the default value of each element type.

Parameters
arrayThe array whose elements need to be cleared.
indexThe starting index of the range of elements to clear.
lengthThe number of elements to clear.
Exceptions
xtd::index_out_of_range_exceptionThe sum of `index` and `length` is greater than the size of array.
Examples
The following example uses the xtd::array::clear method to reset integer values in a one-dimensional, two-dimensional, and three-dimensional array.

◆ constrained_copy() [1/2]

template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void xtd::array<>::constrained_copy ( const array< source_type_t, source_rank, source_allocator_t > & source_array,
const xtd::array< xtd::size > & source_indexes,
array< destination_type_t, destination_rank, destination_allocator_t > & destination_array,
const xtd::array< xtd::size > & destination_indexes,
xtd::size length )
inlinestatic

Copies a range of elements from an xtd::array starting at the specified source index and pastes them to another xtd::array starting at the specified destination index. Guarantees that all changes are undone if the copy does not succeed completely.

Parameters
source_arrayThe xtd::array that contains the data to copy.
source_indexesAn array of xtd::size that represents the index in source_array at which copying begins.
destination_arrayThe xtd::array that receives the data.
destination_indexesAn array of xtd::size that represents the index in destination_array at which storing begins.
lengthAn xtd::size that represents the number of elements to copy.
Exceptions
xtd::rank_exception`source_array` and `destination_array` have different ranks.
xtd::argument_out_of_range_excpetion`source_index` is less than the lower bound of the first dimension of `source_array`.
-or-
`destination_index` is less than the lower bound of the first dimension of `destination_array`.
xtd::argument_exception`length` is greater than the number of elements from `source_index` to the end of `source_array`.
-or-
`length` is greater than the number of elements from `destination_index` to the end of `destination_array`.

◆ constrained_copy() [2/2]

template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void xtd::array<>::constrained_copy ( const array< source_type_t, source_rank, source_allocator_t > & source_array,
xtd::size source_index,
array< destination_type_t, destination_rank, destination_allocator_t > & destination_array,
xtd::size destination_index,
xtd::size length )
inlinestatic

Copies a range of elements from an xtd::array starting at the specified source index and pastes them to another xtd::array starting at the specified destination index. Guarantees that all changes are undone if the copy does not succeed completely.

Parameters
source_arrayThe xtd::array that contains the data to copy.
source_indexAn xtd::size that represents the index in source_array at which copying begins.
destination_arrayThe xtd::array that receives the data.
destination_indexAn xtd::size that represents the index in destination_array at which storing begins.
lengthAn xtd::size that represents the number of elements to copy.
Exceptions
xtd::rank_exception`source_array` and `destination_array` have different ranks.
xtd::argument_out_of_range_excpetion`source_index` is less than the lower bound of the first dimension of `source_array`.
-or-
`destination_index` is less than the lower bound of the first dimension of `destination_array`.
xtd::argument_exception`length` is greater than the number of elements from `source_index` to the end of `source_array`.
-or-
`length` is greater than the number of elements from `destination_index` to the end of `destination_array`.

◆ convert_all()

template<class output_t, class input_t, xtd::size rank, class allocator_t, class converter_t, class destination_allocator_t = xtd::collections::generic::helpers::allocator<output_t>>
static xtd::array< output_t, rank, destination_allocator_t > xtd::array<>::convert_all ( const xtd::array< input_t, rank, allocator_t > & array,
converter_t converter )
inlinestatic

Converts an array of one type to an array of another type.

Parameters
arrayThe zero-based xtd::array <type_t> to convert to a target type.
converterA xtd::converter <output_t, input_t> that converts each element from one type to another type.
Returns
An array of the target type containing the converted elements from the source array.
Remarks
The xtd::converter <output_t, input_t> is a delegate to a method that converts an object to the target type. The elements of array are individually passed to the xtd::converter <output_t, input_t>, and the converted elements are saved in the new array.
The source array remains unchanged.
This method is an O(n) operation, where n is the xtd::basic_array::length of array.

◆ copy() [1/4]

template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void xtd::array<>::copy ( const array< source_type_t, source_rank, source_allocator_t > & source_array,
const array< destination_type_t, destination_rank, destination_allocator_t > & destination_array )
inlinestatic

Copies a range of elements from an xtd::array starting at the first element and pastes them into another xtd::array starting at the first element. The length is specified as an xtd::size.

Parameters
source_arrayThe xtd::array that contains the data to copy.
destination_arrayThe xtd::rray that receives the data.
lengthAn xtd::size that represents the number of elements to copy.
Exceptions
xtd::argument_out_of_range_exceptionThe `length` is greater than `source_array` size.<ber>-or-
The `length` is greater than `destination_array` size.

◆ copy() [2/4]

template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void xtd::array<>::copy ( const array< source_type_t, source_rank, source_allocator_t > & source_array,
const array< destination_type_t, destination_rank, destination_allocator_t > & destination_array,
xtd::size length )
inlinestatic

Copies a range of elements from an xtd::array starting at the first element and pastes them into another xtd::array starting at the first element. The length is specified as an xtd::size.

Parameters
source_arrayThe xtd::array that contains the data to copy.
destination_arrayThe xtd::rray that receives the data.
lengthAn xtd::size that represents the number of elements to copy.
Exceptions
xtd::argument_out_of_range_exceptionThe `length` is greater than `source_array` size.<ber>-or-
The `length` is greater than `destination_array` size.

◆ copy() [3/4]

template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void xtd::array<>::copy ( const array< source_type_t, source_rank, source_allocator_t > & source_array,
const xtd::array< xtd::size > & source_indexes,
const array< destination_type_t, destination_rank, destination_allocator_t > & destination_array,
const xtd::array< xtd::size > & destination_indexes,
xtd::size length )
inlinestatic

Copies a range of elements from an xtd::array starting at the specified source index and pastes them to another xtd::array starting at the specified destination index. The length and the indexes are specified as 64-bit integers.

Parameters
source_arrayThe xtd::rray that contains the data to copy.
source_indexAn xtd::size that represents the index in source_array at which copying begins.
destination_arrayThe xtd::array that receives the data.
destination_indexAn xtd::size that represents the index in destination_array at which storing begins.
lengthAn xtd::size that represents the number of elements to copy.
Exceptions
xtd::argument_out_of_range_exceptionThe sum of the `source_index` and `length` is greater than `source_array` size.<ber>-or-
The sum of the `destination_index` and `length` is greater than `destination_array` size.

◆ copy() [4/4]

template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
static void xtd::array<>::copy ( const array< source_type_t, source_rank, source_allocator_t > & source_array,
xtd::size source_index,
const array< destination_type_t, destination_rank, destination_allocator_t > & destination_array,
xtd::size destination_index,
xtd::size length )
inlinestatic

Copies a range of elements from an xtd::array starting at the specified source index and pastes them to another xtd::array starting at the specified destination index. The length and the indexes are specified as 64-bit integers.

Parameters
source_arrayThe xtd::rray that contains the data to copy.
source_indexAn xtd::size that represents the index in source_array at which copying begins.
destination_arrayThe xtd::array that receives the data.
destination_indexAn xtd::size that represents the index in destination_array at which storing begins.
lengthAn xtd::size that represents the number of elements to copy.
Exceptions
xtd::argument_out_of_range_exceptionThe sum of the `source_index` and `length` is greater than `source_array` size.<ber>-or-
The sum of the `destination_index` and `length` is greater than `destination_array` size.

◆ create_instance() [1/4]

template<class type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::array< type_t, 1, allocator_t > xtd::array<>::create_instance ( xtd::size length)
inlinestatic

Creates a one-dimensional xtd::array <type_t> of the specified Type and length, with zero-based indexing.

Parameters
lengthThe size of the xtd::array <type_t> to create.
Returns
A new one-dimensional xtd::array <type_t> of the specified Type with the specified length, using zero-based indexing.
Exceptions
xtd::argument_exceptionelementType is not a valid Type.
xtd::not_supported_exceptionelementType is not supported. For example, Void is not supported. -or- elementType is an open generic type.
xtd::argument_out_of_range_exceptionlength is less than zero.
Remarks
Unlike most classes, xtd::array <type_t> provides the create_instance method, instead of public constructors, to allow for late bound access.
Pointer-type elements are initialized to null. Value-type elements are initialized to zero.
This method is an O(n) operation, where n is length.
Parameters
EXamplesThe following code example shows how to create and initialize a one-dimensional xtd::array <type_t>.

◆ create_instance() [2/4]

template<class type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::array< type_t, 2, allocator_t > xtd::array<>::create_instance ( xtd::size length1,
xtd::size length2 )
inlinestatic

Creates a two-dimensional xtd::array <type_t> of the specified Type and dimension lengths, with zero-based indexing.

Parameters
length1The size of the first dimension of the xtd::array <type_t> to create.
length2The size of the second dimension of the xtd::array <type_t> to create.
Returns
A new two-dimensional xtd::array <type_t> of the specified Type with the specified length for each dimension, using zero-based indexing.
Exceptions
xtd::argument_exceptionelementType is not a valid Type.
xtd::not_supported_exceptionelementType is not supported. For example, Void is not supported. -or- elementType is an open generic type.
xtd::argument_out_of_range_exceptionlength1 is less than zero. -or- xtd::argument_out_of_range_exception length2 is less than zero.
Remarks
Unlike most classes, xtd::array <type_t> provides the create_instance method, instead of public constructors, to allow for late bound access.
Pointer-type elements are initialized to null. Value-type elements are initialized to zero.
This method is an O(n) operation, where n is length.
Parameters
EXamplesThe following code example shows how to create and initialize a two-dimensional xtd::array <type_t>.

◆ create_instance() [3/4]

template<typename type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::array< type_t, 3, allocator_t > xtd::array<>::create_instance ( xtd::size length1,
xtd::size length2,
xtd::size length3 )
inlinestatic

Creates a three-dimensional xtd::array <type_t> of the specified Type and dimension lengths, with zero-based indexing.

Parameters
length1The size of the first dimension of the xtd::array <type_t> to create.
length2The size of the second dimension of the xtd::array <type_t> to create.
length3The size of the third dimension of the xtd::array <type_t> to create.
Returns
A new three-dimensional xtd::array <type_t> of the specified Type with the specified length for each dimension, using zero-based indexing.
Exceptions
xtd::argument_exceptionelementType is not a valid Type.
xtd::not_supported_exceptionelementType is not supported. For example, Void is not supported. -or- elementType is an open generic type.
xtd::argument_out_of_range_exceptionlength1 is less than zero. -or- xtd::argument_out_of_range_exception length2 is less than zero. -or- xtd::argument_out_of_range_exception length3 is less than zero.
Remarks
Unlike most classes, xtd::array <type_t> provides the create_instance method, instead of public constructors, to allow for late bound access.
Pointer-type elements are initialized to null. Value-type elements are initialized to zero.
This method is an O(n) operation, where n is length.
Parameters
EXamplesThe following code example shows how to create and initialize a three-dimensional xtd::array <type_t>.

◆ create_instance() [4/4]

template<class type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::array< type_t, rank, allocator_t > xtd::array<>::create_instance ( const xtd::array< xtd::size > & lengths)
inlinestatic

Creates a multidimensional xtd::array <type_t> of the specified Type and dimension lengths, with zero-based indexing. The dimension lengths are specified in an array of 32-bit integers.

Parameters
Anarray of 32-bit integers that represent the size of each dimension of the xtd::array <type_t> to create.
Returns
A new multidimensional xtd::array <type_t> of the specified Type with the specified length for each dimension, using zero-based indexing.
Exceptions
xtd::argument_exceptionelementType is not a valid Type.
xtd::not_supported_exceptionelementType is not supported. For example, Void is not supported. -or- elementType is an open generic type.
xtd::argument_out_of_range_exceptionlength1 is less than zero. -or- xtd::argument_out_of_range_exception length2 is less than zero. -or- xtd::argument_out_of_range_exception length3 is less than zero.
Remarks
Unlike most classes, xtd::array <type_t> provides the create_instance method, instead of public constructors, to allow for late bound access.
The number of elements in the lengths array must equal the number of dimensions in the new xtd::array <type_t>. Each element of the lengths array must specify the length of the corresponding dimension in the new xtd::array <type_t>.
Pointer-type elements are initialized to null. Value-type elements are initialized to zero.
This method is an O(n) operation, where n is length.

◆ exists()

template<class type_t, xtd::size rank, class allocator_t, class predicate_t>
static bool xtd::array<>::exists ( const xtd::array< type_t, rank, allocator_t > & array,
predicate_t match )
inlinestatic

Determines whether the xtd::array <type_t> contains elements that match the conditions defined by the specified predicate..

Parameters
matchThe xtd::predicate function that defines the conditions of the elements to search for.
Returns
true if the xtd::array <type_t> contains one or more elements that match the conditions defined by the specified predicate; otherwise, false.
Remarks
The xtd::predicate is a method that returns true if the object passed to it matches the conditions defined in the pointer function. The elements of the current xtd::array <type_t> are individually passed to the Predicate pointer function, and processing is stopped when a match is found.
This method is an O(n) operation, where n is Count.

◆ index_of() [1/3]

template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::size xtd::array<>::index_of ( const xtd::array< type_t, rank, allocator_t > & array,
const type_t & value )
inlinestaticnoexcept

Determines the index of a specific item in the array specified.

Parameters
arrayThe object to locate in the array.
valueThe object to locate in the array.
Returns
The index of value if found in the array; otherwise, -1.
Examples
The following code example shows how to determine the index of the first occurrence of a specified element.

◆ index_of() [2/3]

template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::size xtd::array<>::index_of ( const xtd::array< type_t, rank, allocator_t > & array,
const type_t & value,
xtd::size index )
inlinestatic

Determines the index of a specific item in the array specified.

Parameters
arrayThe object to locate in the array.
valueThe object to locate in the array.
indexThe zero-based starting index of the search.
Returns
The index of value if found in the array; otherwise, -1.
Exceptions
xtd::argument_out_of_range_exceptionThe parameters `index` is less than 0.
Examples
The following code example shows how to determine the index of the first occurrence of a specified element.

◆ index_of() [3/3]

template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
static xtd::size xtd::array<>::index_of ( const xtd::array< type_t, rank, allocator_t > & array,
const type_t & value,
xtd::size index,
xtd::size count )
inlinestatic

Determines the index of a specific item in the array specified.

Parameters
arrayThe object to locate in the array.
valueThe object to locate in the array.
indexThe zero-based starting index of the search.
countThe number of elements in the section to search
Returns
The index of value if found in the array; otherwise, -1.
Exceptions
xtd::argument_out_of_range_exceptionThe parameters `index` and `count` do not specify a valid section in the 'array'.
Examples
The following code example shows how to determine the index of the first occurrence of a specified element.

◆ resize()

template<class type_t, class allocator_t>
static void xtd::array<>::resize ( xtd::array< type_t, 1, allocator_t > & array,
int32 new_size )
inlinestatic

Changes the number of elements of a one-dimensional array to the specified new size.

Parameters
arrayThe one-dimensional, zero-based array to resize, or null to create a new array with the specified size.
newSizeThe size of the new array.
Exceptions
xtd::argument_out_of_range_exceptionnewSize is less than zero.
Remarks
This method allocates a new array with the specified size, copies elements from the old array to the new one, and then replaces the old array with the new one. array must be a one-dimensional array.
If newSize is greater than the Length of the old array, a new array is allocated and all the elements are copied from the old array to the new one. If newSize is less than the Length of the old array, a new array is allocated and elements are copied from the old array to the new one until the new one is filled; the rest of the elements in the old array are ignored. If newSize is equal to the Length of the old array, this method does nothing.
This method is an O(n) operation, where n is old size.

◆ reverse() [1/2]

template<class type_t, class allocator_t>
static void xtd::array<>::reverse ( xtd::array< type_t, 1, allocator_t > & array)
inlinestatic

Reverses the order of the elements in the entire xtd::basic_array.

Remarks
This method uses std::reverse to reverse the order of the elements, such that the element at xtd::basic_array <type_t>[i], where i is any index within the range, moves to xtd::basic_array <type_t>[j], where j equals index plus index plus count minus i minus 1.
This method is an O(n) operation, where n is xtd::basic_array::count.

◆ reverse() [2/2]

template<class type_t, class allocator_t>
static void xtd::array<>::reverse ( xtd::array< type_t, 1, allocator_t > & array,
int32 index,
int32 count )
inlinestatic

Reverses the order of the elements in the specified range.

Parameters
indexThe zero-based starting index of the range to reverse.
countThe number of elements in the range to reverse.
Exceptions
xtd::argument_out_of_range_exception`index` and `count` do not denote a valid range of elements in the xtd::basic_array.
Remarks
This method uses std::reverse to reverse the order of the elements, such that the element at xtd::basic_array <type_t>[i], where i is any index within the range, moves to xtd::basic_array <type_t>[j], where j equals index plus index plus count minus i minus 1.
This method is an O(n) operation, where n is count.

◆ rank()

xtd::size xtd::array< type_t, rank_, allocator_t >::rank ( ) const
inlineoverridevirtualnoexcept

Gets the rank (number of dimensions) of the array.

Returns
The rank (number of dimensions) of the array.
Examples
The following code example demonstrates methods to get the rank of an array.

Reimplemented from xtd::basic_array< type_t, allocator_t >.

◆ to_string()

xtd::string xtd::array< type_t, rank_, allocator_t >::to_string ( ) const
overridevirtualnoexcept

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

Returns
A string that represents the current object.

Reimplemented from xtd::object.

◆ operator=() [1/2]

array & xtd::array< type_t, rank_, allocator_t >::operator= ( const array<> & )
default

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/2]

array & xtd::array< type_t, rank_, allocator_t >::operator= ( 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.

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

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