Skip to content

ludus::foundation::core::FixedArray

Ludus Wiki · API overview · Browse API

Class

Bounded contiguous sequence in inline storage; never allocates.
Elements [0, GetSize()) are live; the remaining Count - GetSize() slots are raw storage. Adding to a full array fails through the Try operations and changes nothing. Ordered insertion and removal invalidate element borrows at and after the affected position; borrows never move otherwise, because the storage is inline. Moving the whole FixedArray moves its elements, so borrows do not follow a move. A moved-from array is empty.

Note

One owner; synchronize access externally. Element destruction must not throw.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

#include <ludus/foundation/containers/fixed_array.hpp>
template <typename ElementType, usize Count>
class ludus::foundation::core::FixedArray

Types

ValueType

using ludus::foundation::core::FixedArray< ElementType, Count >::ValueType = ElementType
Stored element type.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

SizeType

using ludus::foundation::core::FixedArray< ElementType, Count >::SizeType = usize
Size and index type.

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

Iterator

using ludus::foundation::core::FixedArray< ElementType, Count >::Iterator = ElementType*
Contiguous mutable iterator into the live prefix.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

ConstIterator

using ludus::foundation::core::FixedArray< ElementType, Count >::ConstIterator = const ElementType*
Contiguous read-only iterator into the live prefix.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

Methods

FixedArray

ludus::foundation::core::FixedArray< ElementType, Count >::FixedArray() noexcept=default
Empty array; no element is constructed.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

FixedArray

ludus::foundation::core::FixedArray< ElementType, Count >::FixedArray(const FixedArray &other)
requires std::is_copy_constructible_v<ElementType>
Copy-construct each of other's live elements.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

FixedArray

ludus::foundation::core::FixedArray< ElementType, Count >::FixedArray(FixedArray &&other) noexcept
requires std::is_nothrow_move_constructible_v<ElementType>
Move-construct each of other's live elements, then leave other empty.
Borrows into other keep referring to other's slots, which no longer hold live elements.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

operator=

FixedArray & ludus::foundation::core::FixedArray< ElementType, Count >::operator=(const FixedArray &other)
requires std::is_copy_constructible_v<ElementType> && std::is_copy_assignable_v<ElementType>
Replace the contents with copies of other's elements.
Assigns the common prefix, constructs additional elements and destroys any surplus. Self-assignment does nothing.

Related types: FixedArray

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

operator=

FixedArray & ludus::foundation::core::FixedArray< ElementType, Count >::operator=(FixedArray &&other) noexcept
requires std::is_nothrow_move_constructible_v<ElementType> && std::is_nothrow_move_assignable_v<ElementType>
Replace the contents by moving other's elements, then leave other empty.
Self-assignment does nothing.

Related types: FixedArray

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

~FixedArray

ludus::foundation::core::FixedArray< ElementType, Count >::~FixedArray()=default
requires std::is_trivially_destructible_v<ElementType>
Trivial destruction when ElementType is trivially destructible.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

~FixedArray

ludus::foundation::core::FixedArray< ElementType, Count >::~FixedArray()
Destroy the live elements.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

GetSize

LUDUS_INLINE usize ludus::foundation::core::FixedArray< ElementType, Count >::GetSize() const noexcept
Number of live elements.

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

IsEmpty

LUDUS_INLINE bool ludus::foundation::core::FixedArray< ElementType, Count >::IsEmpty() const noexcept
True when no element is live.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

IsFull

LUDUS_INLINE bool ludus::foundation::core::FixedArray< ElementType, Count >::IsFull() const noexcept
True when every slot is live, so the Try add/insert operations fail. Always true for Count 0.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

GetData

LUDUS_INLINE ElementType * ludus::foundation::core::FixedArray< ElementType, Count >::GetData() noexcept
First slot of the inline storage, or nullptr when Count is 0. Valid for the array's lifetime.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

GetData

LUDUS_INLINE const ElementType * ludus::foundation::core::FixedArray< ElementType, Count >::GetData() const noexcept
Read-only first slot of the inline storage, or nullptr when Count is 0.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

operator[]

LUDUS_INLINE ElementType & ludus::foundation::core::FixedArray< ElementType, Count >::operator[](usize index) noexcept
Element at index.

Precondition

index < GetSize() (asserted in checked builds).

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

operator[]

LUDUS_INLINE const ElementType & ludus::foundation::core::FixedArray< ElementType, Count >::operator[](usize index) const noexcept
Read-only element at index.

Precondition

index < GetSize() (asserted in checked builds).

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

GetFirst

LUDUS_INLINE ElementType & ludus::foundation::core::FixedArray< ElementType, Count >::GetFirst() noexcept
First element.

Precondition

The array is not empty.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

GetFirst

LUDUS_INLINE const ElementType & ludus::foundation::core::FixedArray< ElementType, Count >::GetFirst() const noexcept
Read-only first element.

Precondition

The array is not empty.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

GetLast

LUDUS_INLINE ElementType & ludus::foundation::core::FixedArray< ElementType, Count >::GetLast() noexcept
Last element.

Precondition

The array is not empty.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

GetLast

LUDUS_INLINE const ElementType & ludus::foundation::core::FixedArray< ElementType, Count >::GetLast() const noexcept
Read-only last element.

Precondition

The array is not empty.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

begin

LUDUS_INLINE Iterator ludus::foundation::core::FixedArray< ElementType, Count >::begin() noexcept
Range-for/standard interop: first live element.

Related types: Iterator

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

begin

LUDUS_INLINE ConstIterator ludus::foundation::core::FixedArray< ElementType, Count >::begin() const noexcept
Range-for/standard interop: read-only first live element.

Related types: ConstIterator

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

cbegin

LUDUS_INLINE ConstIterator ludus::foundation::core::FixedArray< ElementType, Count >::cbegin() const noexcept
Standard interop: read-only first live element.

Related types: ConstIterator

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

end

LUDUS_INLINE Iterator ludus::foundation::core::FixedArray< ElementType, Count >::end() noexcept
Range-for/standard interop: one past the last live element.

Related types: Iterator

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

end

LUDUS_INLINE ConstIterator ludus::foundation::core::FixedArray< ElementType, Count >::end() const noexcept
Range-for/standard interop: read-only one past the last live element.

Related types: ConstIterator

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

cend

LUDUS_INLINE ConstIterator ludus::foundation::core::FixedArray< ElementType, Count >::cend() const noexcept
Standard interop: read-only one past the last live element.

Related types: ConstIterator

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

data

LUDUS_INLINE ElementType * ludus::foundation::core::FixedArray< ElementType, Count >::data() noexcept
Standard interop spelling of GetData().

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

data

LUDUS_INLINE const ElementType * ludus::foundation::core::FixedArray< ElementType, Count >::data() const noexcept
Standard interop spelling of the read-only GetData().

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

size

LUDUS_INLINE usize ludus::foundation::core::FixedArray< ElementType, Count >::size() const noexcept
Standard interop spelling of GetSize().

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

TryAdd

bool ludus::foundation::core::FixedArray< ElementType, Count >::TryAdd(const ElementType &value)
Append a copy of value unless the array is full.
value may refer to an element of this array.

Returns

False when full; the array and value are unchanged.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

TryAdd

bool ludus::foundation::core::FixedArray< ElementType, Count >::TryAdd(ElementType &&value)
Append by moving value unless the array is full.

Returns

False when full; the array is unchanged and value is not moved from.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

TryAddInPlace

template <typename... Args>
ElementType * ludus::foundation::core::FixedArray< ElementType, Count >::TryAddInPlace(Args &&... args)
Append an element constructed from args unless the array is full.
No existing element moves, so args may refer to elements of this array.

Returns

The new element, or nullptr when full with the array and args untouched.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

TryAddRange

bool ludus::foundation::core::FixedArray< ElementType, Count >::TryAddRange(std::span< const ElementType > items)
Append copies of every element of items, or none of them.

Precondition

items does not overlap this array's storage (asserted).

Returns

False when the elements do not all fit; the array is unchanged.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

TryInsertAt

ElementType * ludus::foundation::core::FixedArray< ElementType, Count >::TryInsertAt(usize index, const ElementType &value)
Insert a copy of value at index, shifting later elements, unless the array is full.

Precondition

index <= GetSize(). value may refer to an element of this array.

Returns

The inserted element, or nullptr when full with the array unchanged.

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

TryInsertAt

ElementType * ludus::foundation::core::FixedArray< ElementType, Count >::TryInsertAt(usize index, ElementType &&value)
Move value into index, shifting later elements, unless the array is full.

Precondition

index <= GetSize().

Returns

The inserted element, or nullptr when full with the array unchanged and value not moved from.

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

TryInsertAtInPlace

template <typename... Args>
ElementType * ludus::foundation::core::FixedArray< ElementType, Count >::TryInsertAtInPlace(usize index, Args &&... args)
Insert an element constructed from args at index, shifting later elements.
The element is materialized before any element moves, so args may refer to elements of this array. Invalidates borrows at and after index.

Precondition

index <= GetSize().

Returns

The inserted element, or nullptr when full with the array and args untouched.

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

RemoveLast

void ludus::foundation::core::FixedArray< ElementType, Count >::RemoveLast() noexcept
Destroy the last element.

Precondition

The array is not empty.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

RemoveAt

void ludus::foundation::core::FixedArray< ElementType, Count >::RemoveAt(usize index) noexcept
Order-preserving removal at index; later elements shift left. O(n).
Invalidates borrows at and after index.

Precondition

index < GetSize().

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

RemoveAtSwap

void ludus::foundation::core::FixedArray< ElementType, Count >::RemoveAtSwap(usize index) noexcept
O(1) removal that moves the last element into index; order is not preserved.

Precondition

index < GetSize().

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

Clear

void ludus::foundation::core::FixedArray< ElementType, Count >::Clear() noexcept
Destroy every live element. The capacity is unchanged.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

operator std::span\< ElementType >

ludus::foundation::core::FixedArray< ElementType, Count >::operator std::span< ElementType >() noexcept
Borrow the live elements as a mutable span; invalidated with element borrows.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

operator std::span\< const ElementType >

ludus::foundation::core::FixedArray< ElementType, Count >::operator std::span< const ElementType >() const noexcept
Borrow the live elements as a read-only span; invalidated with element borrows.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

AsSpan

std::span< ElementType > ludus::foundation::core::FixedArray< ElementType, Count >::AsSpan() noexcept
Mutable span over the live elements.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

AsSpan

std::span< const ElementType > ludus::foundation::core::FixedArray< ElementType, Count >::AsSpan() const noexcept
Read-only span over the live elements.

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

Static methods

GetCapacity

static LUDUS_INLINE constexpr usize ludus::foundation::core::FixedArray< ElementType, Count >::GetCapacity() noexcept
Fixed capacity; always Count.

Related types: usize

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp

Members

operator==

bool operator==(const FixedArray &left, const FixedArray &right)
Element-wise equality of the live elements; arrays of different sizes are unequal.

Related types: FixedArray

Declared in modules/foundation/containers/include/ludus/foundation/containers/fixed_array.hpp