xtd 0.2.0
Loading...
Searching...
No Matches
xtd::array_<> Class Reference
Inheritance diagram for xtd::array_<>:
xtd::static_object

Definition

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

Definition
template<typename type_t, xtd::size rank_, typename allocator_t>
class array : public xtd::basic_array<type_t, allocator_t>;
Base object that represent array.
Definition basic_array.h:27
std::vector< type_t > array
Definition __array_definition.h:18
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.

Public Static Methods

template<typename type_t , typename 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.
 

Member Function Documentation

◆ as_read_only()

template<typename type_t , typename 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)
static

Returns a read-only wrapper for the specified array.

Parameters
arrayThe one-dimensional, zero-based array to wrap in a read-only ReadOnlyCollection<type_t> wrapper.
Returns
A read-only ReadOnlyCollection<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 ReadOnlyCollection<type_t>.

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