Class Subspace :: sus :: collections :: Array

template <class T, size_t N>
class Array final
{ ... };

A collection of objects of type T, with a fixed size N.

An Array can not be larger than isize::MAX, as subtracting a pointer at a greater distance results in Undefined Behaviour.

Static Methods

Array()
requires
sus::construct::Default<T>

Default constructor of Array which default-constructs each object T in the array.

This satisifies Default for the Array<T, N> if Default is satisifed for T.

template <class... Ts>
Array(Ts&&... ts)
requires
std::convertible_to<T>...
sizeof...(Ts) == N
N > 0u

Constructs an Array with N elements from the N arguments given to the constructor.

Array(Array<T, N>&&)
requires
N == 0
sus::mem::Move<T>
Array(Array<T, N>&& o)
requires
N > 0
sus::mem::Move<T>
Array(Array<T, N>&&)
requires
!::sus::mem::Move<T>
deleted
static auto with_initializer(FnMut<T()> auto f) -> Array<T, N>

Constructs an Array with N elements, where each element is constructed from the given closure.

template <class U>
static auto with_value(const U& t) -> Array<T, N>
requires
std::convertible_to<U, T>
sus::mem::Copy<T>

Constructs an Array with N elements from a single argument, repeatedly using it to construct each element. The given argument must be Copy in order to do this.

To construct an Array from a single value that is Clone but not Copy, use with_initializer([&x]() -> T { return sus::clone(x); });

Methods

auto as_mut_ptr() & -> T*
requires
N > 0

Returns a mutable pointer to the first element in the array.

auto as_ptr() const& -> const T*
requires
N > 0
auto as_ptr() && -> const T*
deleted

Returns a const pointer to the first element in the array.

auto as_slice() const& -> Slice<T>
auto as_slice() && -> Slice<T>
deleted
auto clone() const& -> Array<T, N>
requires
sus::mem::Clone<T>
auto clone_from(const Array<T, N>& source) & -> void
requires
sus::mem::Clone<T>
auto get(sus::usize i) const& -> Option<const T&>
requires
N > 0
auto get(sus::usize i) && -> Option<const T&>
deleted

Returns a const reference to the element at index i.

auto get_mut(sus::usize i) & -> Option<T&>
requires
N > 0

Returns a mutable reference to the element at index i.

auto get_unchecked(UnsafeFnMarker, sus::usize i) const& -> const T&
requires
N > 0
auto get_unchecked(UnsafeFnMarker, sus::usize i) && -> const T&
deleted

Returns a const reference to the element at index i.

Safety

The index i must be inside the bounds of the array or Undefined Behaviour results.

auto get_unchecked_mut(UnsafeFnMarker, sus::usize i) & -> T&
requires
N > 0

Returns a mutable reference to the element at index i.

Safety

The index i must be inside the bounds of the array or Undefined Behaviour results.

template <int &... , class U = T>
auto into_iter() && -> ArrayIntoIter<U, N>
requires
sus::mem::Move<T>

Converts the array into an iterator that consumes the array and returns each element in the same order they appear in the array.

auto iter() const& -> SliceIter<const T&>
auto iter() && -> SliceIter<const T&>
deleted

Returns an iterator over all the elements in the array, visited in the same order they appear in the array. The iterator gives const access to each element.

Returns an iterator over all the elements in the array, visited in the same order they appear in the array. The iterator gives mutable access to each element.

auto len() const& -> sus::usize

Returns the number of elements in the array.

template <class MapFn>
auto map(MapFn f) && -> Array<sus::fn::ReturnOnce<MapFn, T&&>, N>
requires
sus::fn::FnMut<MapFn, ::sus::fn::NonVoid (T &&)>
N > 0

Consumes the array, and returns a new array, mapping each element of the array to a new type with the given function.

To just walk each element and map them, consider using iter() and Iterator::map. This does not require consuming the array.

Conversions

operator Slice() const&
requires
N == 0u
operator Slice() const&
requires
N > 0u
operator Slice() &&
deleted
operator Slice() &
requires
N == 0u
operator Slice() &
requires
N > 0u
operator SliceMut() &
requires
N == 0u
operator SliceMut() &
requires
N > 0u

Operators

auto operator=(Array<T, N>&&) -> Array<T, N>&
requires
N == 0
sus::mem::Move<T>
auto operator=(Array<T, N>&& o) -> Array<T, N>&
requires
sus::mem::Move<T>
auto operator=(Array<T, N>&&) -> Array<T, N>&
requires
!::sus::mem::Move<T>
deleted
template <class U>
auto operator==(const Array<U, N>& r) const& -> bool
requires
sus::cmp::Eq<T, U>
sus::cmp::Eq<T>

Satisfies the Eq<Array<T, N>, Array<U, N>> concept.

auto operator[](sus::usize i) const& -> const T&
auto operator[](sus::usize i) && -> const T&
deleted
auto operator[](sus::usize i) & -> T&