Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::cnt::sarr< T, N > Class Template Reference

Fixed-size stack array with AoS storage. Interface compatiblity with std::array where it matters. More...

#include <sarray_impl.h>

Public Types

using value_type = T
 Element type stored by the container.
 
using reference = T &
 Mutable element reference type.
 
using const_reference = const T &
 Read-only element reference type.
 
using pointer = T *
 Mutable element pointer type.
 
using const_pointer = const T *
 Read-only element pointer type.
 
using view_policy = mem::data_view_policy_aos< T >
 Data-layout access policy used by the container.
 
using difference_type = sarr_detail::difference_type
 Type used for iterator differences.
 
using size_type = sarr_detail::size_type
 Unsigned type used for sizes and indices.
 
using iterator = pointer
 Mutable random-access iterator type.
 
using const_iterator = const_pointer
 Read-only random-access iterator type.
 
using iterator_category = core::random_access_iterator_tag
 Iterator category exposed by the container.
 

Public Member Functions

constexpr sarr (core::zero_t) noexcept
 Explicit value-initialization constructor for call sites that want zero/value initialization to be obvious.
 
template<typename InputIt >
constexpr sarr (InputIt first, InputIt last) noexcept
 Constructs a container from an iterator range.
 
constexpr sarr (std::initializer_list< T > il)
 Constructs a container from an initializer list.
 
constexpr sarr (const sarr &)=default
 
constexpr sarr (sarr &&) noexcept=default
 
sarroperator= (std::initializer_list< T > il)
 Replaces the elements from an initializer list.
 
constexpr sarroperator= (const sarr &other)
 Copy-assigns the container.
 
constexpr sarroperator= (sarr &&other) noexcept
 Move-assigns the container.
 
GAIA_NODISCARD constexpr pointer data () noexcept
 Returns a pointer to the element storage.
 
GAIA_NODISCARD constexpr const_pointer data () const noexcept
 Returns a pointer to the element storage.
 
GAIA_NODISCARD constexpr decltype(autooperator[] (size_type pos) noexcept
 Accesses an element without bounds checking in optimized builds.
 
GAIA_NODISCARD constexpr decltype(autooperator[] (size_type pos) const noexcept
 Accesses an element without bounds checking in optimized builds.
 
GAIA_NODISCARD constexpr size_type size () const noexcept
 Returns the number of elements.
 
GAIA_NODISCARD constexpr bool empty () const noexcept
 Checks whether the container has no elements.
 
GAIA_NODISCARD constexpr size_type capacity () const noexcept
 Returns the number of elements that fit without reallocation.
 
GAIA_NODISCARD constexpr size_type max_size () const noexcept
 Returns the maximum number of elements supported by this container.
 
GAIA_NODISCARD constexpr decltype(autofront () noexcept
 Accesses the first element.
 
GAIA_NODISCARD constexpr decltype(autofront () const noexcept
 Accesses the first element.
 
GAIA_NODISCARD constexpr decltype(autoback () noexcept
 Accesses the last element.
 
GAIA_NODISCARD constexpr decltype(autoback () const noexcept
 Accesses the last element.
 
GAIA_NODISCARD constexpr auto begin () noexcept
 Returns an iterator to the first element.
 
GAIA_NODISCARD constexpr auto begin () const noexcept
 Returns an iterator to the first element.
 
GAIA_NODISCARD constexpr auto cbegin () const noexcept
 Returns a read-only iterator to the first element.
 
GAIA_NODISCARD constexpr auto rbegin () noexcept
 Returns a reverse traversal iterator to the last element.
 
GAIA_NODISCARD constexpr auto rbegin () const noexcept
 Returns a reverse traversal iterator to the last element.
 
GAIA_NODISCARD constexpr auto crbegin () const noexcept
 Returns a read-only reverse traversal iterator to the last element.
 
GAIA_NODISCARD constexpr auto end () noexcept
 Returns an iterator one past the last element.
 
GAIA_NODISCARD constexpr auto end () const noexcept
 Returns an iterator one past the last element.
 
GAIA_NODISCARD constexpr auto cend () const noexcept
 Returns a read-only iterator one past the last element.
 
GAIA_NODISCARD constexpr auto rend () noexcept
 Returns the reverse traversal sentinel preceding the first element.
 
GAIA_NODISCARD constexpr auto rend () const noexcept
 Returns the reverse traversal sentinel preceding the first element.
 
GAIA_NODISCARD constexpr auto crend () const noexcept
 Returns the read-only reverse traversal sentinel preceding the first element.
 
GAIA_NODISCARD constexpr bool operator== (const sarr &other) const
 Compares two containers element by element.
 
GAIA_NODISCARD constexpr bool operator!= (const sarr &other) const
 Checks whether two containers differ.
 

Public Attributes

T m_data [N]
 Inline storage backing the container elements.
 

Static Public Attributes

static constexpr size_t value_size = sizeof(T)
 Size of one element in bytes.
 
static constexpr size_type extent = N
 Fixed capacity of the container.
 

Detailed Description

template<typename T, sarr_detail::size_type N>
class gaia::cnt::sarr< T, N >

Fixed-size stack array with AoS storage. Interface compatiblity with std::array where it matters.

Template Parameters
TElement type stored directly in the array.
NNumber of elements and fixed capacity.
Note
This container can be used in constexpr environment.

Constructor & Destructor Documentation

◆ sarr() [1/3]

template<typename T , sarr_detail::size_type N>
constexpr gaia::cnt::sarr< T, N >::sarr ( core::zero_t  )
inlineconstexprnoexcept

Explicit value-initialization constructor for call sites that want zero/value initialization to be obvious.

Note
Even though sarr is an aggregate type and we could zero-initialize by doing sarr<int,10> tmp{}, we keep this function around for design compatibility with other containers that are not aggregate types.

◆ sarr() [2/3]

template<typename T , sarr_detail::size_type N>
template<typename InputIt >
constexpr gaia::cnt::sarr< T, N >::sarr ( InputIt  first,
InputIt  last 
)
inlineconstexprnoexcept

Constructs a container from an iterator range.

Template Parameters
InputItInput iterator type.
Parameters
firstIterator to the first source element.
lastIterator one past the last source element.

◆ sarr() [3/3]

template<typename T , sarr_detail::size_type N>
constexpr gaia::cnt::sarr< T, N >::sarr ( std::initializer_list< T il)
inlineconstexpr

Constructs a container from an initializer list.

Parameters
ilInitializer list supplying the elements.

Member Function Documentation

◆ back() [1/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr decltype(auto) gaia::cnt::sarr< T, N >::back ( ) const
inlineconstexprnoexcept

Accesses the last element.

Returns
Reference to the last element.

◆ back() [2/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr decltype(auto) gaia::cnt::sarr< T, N >::back ( )
inlineconstexprnoexcept

Accesses the last element.

Returns
Reference to the last element.

◆ begin() [1/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::begin ( ) const
inlineconstexprnoexcept

Returns an iterator to the first element.

Returns
Iterator to the first element.

◆ begin() [2/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::begin ( )
inlineconstexprnoexcept

Returns an iterator to the first element.

Returns
Iterator to the first element.

◆ capacity()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr size_type gaia::cnt::sarr< T, N >::capacity ( ) const
inlineconstexprnoexcept

Returns the number of elements that fit without reallocation.

Returns
Current element capacity.

◆ cbegin()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::cbegin ( ) const
inlineconstexprnoexcept

Returns a read-only iterator to the first element.

Returns
Iterator to the first element.

◆ cend()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::cend ( ) const
inlineconstexprnoexcept

Returns a read-only iterator one past the last element.

Returns
Iterator one past the last element.

◆ crbegin()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::crbegin ( ) const
inlineconstexprnoexcept

Returns a read-only reverse traversal iterator to the last element.

Returns
Iterator to the last element.

◆ crend()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::crend ( ) const
inlineconstexprnoexcept

Returns the read-only reverse traversal sentinel preceding the first element.

Returns
Reverse traversal sentinel preceding the first element.

◆ data() [1/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr const_pointer gaia::cnt::sarr< T, N >::data ( ) const
inlineconstexprnoexcept

Returns a pointer to the element storage.

Returns
Pointer to the first element storage location.

◆ data() [2/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr pointer gaia::cnt::sarr< T, N >::data ( )
inlineconstexprnoexcept

Returns a pointer to the element storage.

Returns
Pointer to the first element storage location.

◆ empty()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr bool gaia::cnt::sarr< T, N >::empty ( ) const
inlineconstexprnoexcept

Checks whether the container has no elements.

Returns
True if the container contains no elements.

◆ end() [1/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::end ( ) const
inlineconstexprnoexcept

Returns an iterator one past the last element.

Returns
Iterator one past the last element.

◆ end() [2/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::end ( )
inlineconstexprnoexcept

Returns an iterator one past the last element.

Returns
Iterator one past the last element.

◆ front() [1/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr decltype(auto) gaia::cnt::sarr< T, N >::front ( ) const
inlineconstexprnoexcept

Accesses the first element.

Returns
Reference to the first element.

◆ front() [2/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr decltype(auto) gaia::cnt::sarr< T, N >::front ( )
inlineconstexprnoexcept

Accesses the first element.

Returns
Reference to the first element.

◆ max_size()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr size_type gaia::cnt::sarr< T, N >::max_size ( ) const
inlineconstexprnoexcept

Returns the maximum number of elements supported by this container.

Returns
Maximum supported element count.

◆ operator!=()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr bool gaia::cnt::sarr< T, N >::operator!= ( const sarr< T, N > &  other) const
inlineconstexpr

Checks whether two containers differ.

Parameters
otherContainer to copy or move from.
Returns
True if the containers differ.

◆ operator=() [1/3]

template<typename T , sarr_detail::size_type N>
constexpr sarr & gaia::cnt::sarr< T, N >::operator= ( const sarr< T, N > &  other)
inlineconstexpr

Copy-assigns the container.

Parameters
otherContainer to copy or move from.
Returns
Reference to this container.

◆ operator=() [2/3]

template<typename T , sarr_detail::size_type N>
constexpr sarr & gaia::cnt::sarr< T, N >::operator= ( sarr< T, N > &&  other)
inlineconstexprnoexcept

Move-assigns the container.

Parameters
otherContainer to copy or move from.
Returns
Reference to this container.

◆ operator=() [3/3]

template<typename T , sarr_detail::size_type N>
sarr & gaia::cnt::sarr< T, N >::operator= ( std::initializer_list< T il)
inline

Replaces the elements from an initializer list.

Parameters
ilInitializer list supplying the elements.
Returns
Reference to this container.

◆ operator==()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr bool gaia::cnt::sarr< T, N >::operator== ( const sarr< T, N > &  other) const
inlineconstexpr

Compares two containers element by element.

Parameters
otherContainer to copy or move from.
Returns
True if both containers contain equal elements.

◆ operator[]() [1/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr decltype(auto) gaia::cnt::sarr< T, N >::operator[] ( size_type  pos) const
inlineconstexprnoexcept

Accesses an element without bounds checking in optimized builds.

Parameters
posZero-based element index.
Returns
Reference to the selected element.

◆ operator[]() [2/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr decltype(auto) gaia::cnt::sarr< T, N >::operator[] ( size_type  pos)
inlineconstexprnoexcept

Accesses an element without bounds checking in optimized builds.

Parameters
posZero-based element index.
Returns
Reference to the selected element.

◆ rbegin() [1/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::rbegin ( ) const
inlineconstexprnoexcept

Returns a reverse traversal iterator to the last element.

Returns
Iterator to the last element.

◆ rbegin() [2/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::rbegin ( )
inlineconstexprnoexcept

Returns a reverse traversal iterator to the last element.

Returns
Iterator to the last element.

◆ rend() [1/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::rend ( ) const
inlineconstexprnoexcept

Returns the reverse traversal sentinel preceding the first element.

Returns
Reverse traversal sentinel preceding the first element.

◆ rend() [2/2]

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sarr< T, N >::rend ( )
inlineconstexprnoexcept

Returns the reverse traversal sentinel preceding the first element.

Returns
Reverse traversal sentinel preceding the first element.

◆ size()

template<typename T , sarr_detail::size_type N>
GAIA_NODISCARD constexpr size_type gaia::cnt::sarr< T, N >::size ( ) const
inlineconstexprnoexcept

Returns the number of elements.

Returns
Current element count.

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