tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
array< Type, Size > Struct Template Reference

A container that encapsulates fixed size arrays. More...

#include <etl/array.hpp>

Public Types

using const_iterator = Type const*
 
using const_pointer = Type const*
 
using const_reference = Type const&
 
using const_reverse_iterator = typename etl::reverse_iterator<const_iterator>
 
using difference_type = ptrdiff_t
 
using iterator = Type*
 
using pointer = Type*
 
using reference = Type&
 
using reverse_iterator = typename etl::reverse_iterator<iterator>
 
using size_type = size_t
 
using value_type = Type
 

Public Member Functions

constexpr auto back () const noexcept -> const_reference
 Accesses the last item.
 
constexpr auto back () noexcept -> reference
 Accesses the last item.
 
constexpr auto begin () const noexcept -> const_iterator
 Returns an iterator to the beginning.
 
constexpr auto begin () noexcept -> iterator
 Returns an iterator to the beginning.
 
constexpr auto cbegin () const noexcept -> const_iterator
 Returns an const iterator to the beginning.
 
constexpr auto cend () const noexcept -> const_iterator
 Returns an const iterator to the end.
 
constexpr auto crbegin () const noexcept -> const_reverse_iterator
 Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().
 
constexpr auto crend () const noexcept -> const_reverse_iterator
 Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.
 
constexpr auto data () const noexcept -> const_pointer
 Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).
 
constexpr auto data () noexcept -> pointer
 Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).
 
constexpr auto empty () const noexcept -> bool
 Checks if the container has no elements, i.e. whether begin() == end().
 
constexpr auto end () const noexcept -> const_iterator
 Returns an iterator to the end.
 
constexpr auto end () noexcept -> iterator
 Returns an iterator to the end.
 
constexpr auto fill (const_reference value) -> void
 Assigns the given value value to all elements in the container.
 
constexpr auto front () const noexcept -> const_reference
 Accesses the first item.
 
constexpr auto front () noexcept -> reference
 Accesses the first item.
 
constexpr auto max_size () const noexcept -> size_type
 Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. distance(begin(), end()) for the largest container.
 
constexpr auto operator[] (size_type const pos) const noexcept -> const_reference
 Accesses the specified item with range checking.
 
constexpr auto operator[] (size_type const pos) noexcept -> reference
 Accesses the specified item with range checking.
 
constexpr auto rbegin () const noexcept -> const_reverse_iterator
 Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().
 
constexpr auto rbegin () noexcept -> reverse_iterator
 Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().
 
constexpr auto rend () const noexcept -> const_reverse_iterator
 Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.
 
constexpr auto rend () noexcept -> reverse_iterator
 Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.
 
constexpr auto size () const noexcept -> size_type
 Returns the number of elements in the container, i.e. distance(begin(), end()).
 
constexpr auto swap (array &other) noexcept(is_nothrow_swappable_v< Type >) -> void
 Exchanges the contents of the container with those of other. Does not cause iterators and references to associate with the other container.
 

Public Attributes

TETL_NO_UNIQUE_ADDRESS conditional_t< Size==0, empty_c_array, c_array< Type, Size+size_t{Size==0}> > _buf
 

Friends

constexpr auto operator< (array const &lhs, array const &rhs) -> bool
 Compares the contents of lhs and rhs lexicographically. The comparison is performed by a function equivalent to lexicographical_compare.
 
constexpr auto operator<= (array const &lhs, array const &rhs) -> bool
 
constexpr auto operator== (array const &lhs, array const &rhs) -> bool
 Checks if the contents of lhs and rhs are equal, that is, they have the same number of elements and each element in lhs compares equal with the element in rhs at the same position.
 
constexpr auto operator> (array const &lhs, array const &rhs) -> bool
 
constexpr auto operator>= (array const &lhs, array const &rhs) -> bool
 
constexpr auto swap (array &lhs, array &rhs) noexcept(noexcept(lhs.swap(rhs))) -> void
 Specializes the swap algorithm for array. Swaps the contents of lhs and rhs.
 

Related Symbols

(Note that these are not member symbols.)

template<typename T, typename... U>
 array (T, U...) -> array< T, 1+sizeof...(U)>
 One deduction guide is provided for array to provide an equivalent of experimental::make_array for construction of array from a variadic parameter pack. The program is ill-formed if (is_same_v<T, U> and ...) is not true. Note that it is true when sizeof...(U) is zero.
 
template<size_t Index, typename T, size_t Size>
constexpr auto get (array< T, Size > &&array) noexcept -> T &&
 
template<size_t Index, typename T, size_t Size>
constexpr auto get (array< T, Size > &array) noexcept -> T &
 Extracts the Ith element element from the array. I must be an integer value in range [0, N). This is enforced at compile time as opposed to at() or operator[].
 
template<size_t Index, typename T, size_t Size>
constexpr auto get (array< T, Size > const &&array) noexcept -> T const &&
 
template<size_t Index, typename T, size_t Size>
constexpr auto get (array< T, Size > const &array) noexcept -> T const &
 
template<typename T, etl::size_t Size>
constexpr auto is_tuple_like< etl::array< T, Size > > = true
 
template<typename T, size_t N>
constexpr auto to_array (T(&&a)[N])
 
template<typename T, size_t N>
constexpr auto to_array (T(&a)[N]) -> array< remove_cv_t< T >, N >
 Creates a array from the one dimensional built-in array a. The elements of the array are copy-initialized from the corresponding element of a. Copying or moving multidimensional built-in array is not supported.
 

Detailed Description

template<typename Type, size_t Size>
struct etl::array< Type, Size >

A container that encapsulates fixed size arrays.

This container is an aggregate type with the same semantics as a struct holding a C-style array Type[N] as its only non-static data member. Unlike a C-style array, it doesn't decay to Type* automatically. As an aggregate type, it can be initialized with aggregate-initialization given at most N initializers that are convertible to Type: array<int, 3> a = {1,2,3};

// SPDX-License-Identifier: BSL-1.0
#undef NDEBUG
#include <etl/array.hpp>
#include <etl/cassert.hpp>
#include <etl/iterator.hpp>
auto main() -> int
{
auto src = etl::array{1, 2, 3, 4}; // size & type are deduced
src.fill(42);
assert(etl::all_of(src.begin(), src.end(), [](auto v) { return v == 42; }));
decltype(src) dest = {};
assert(etl::all_of(dest.begin(), dest.end(), [](auto v) { return v == 0; }));
etl::copy(src.begin(), src.end(), dest.begin());
assert(etl::all_of(dest.begin(), dest.end(), [](auto v) { return v == 42; }));
return 0;
}
#define assert(...)
Definition cassert.hpp:19
constexpr auto all_of(InputIt first, InputIt last, Predicate p) -> bool
Checks if unary predicate p returns true for all elements in the range [first, last).
Definition all_of.hpp:15
constexpr auto copy(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Copies the elements in the range, defined by [first, last), to another range beginning at destination...
Definition copy.hpp:18
A container that encapsulates fixed size arrays.
Definition array.hpp:48
constexpr auto fill(const_reference value) -> void
Assigns the given value value to all elements in the container.
Definition array.hpp:207
Examples
array.cpp, numeric.cpp, and set.cpp.

Member Typedef Documentation

◆ const_iterator

template<typename Type, size_t Size>
using const_iterator = Type const*

◆ const_pointer

template<typename Type, size_t Size>
using const_pointer = Type const*

◆ const_reference

template<typename Type, size_t Size>
using const_reference = Type const&

◆ const_reverse_iterator

template<typename Type, size_t Size>
using const_reverse_iterator = typename etl::reverse_iterator<const_iterator>

◆ difference_type

template<typename Type, size_t Size>
using difference_type = ptrdiff_t

◆ iterator

template<typename Type, size_t Size>
using iterator = Type*

◆ pointer

template<typename Type, size_t Size>
using pointer = Type*

◆ reference

template<typename Type, size_t Size>
using reference = Type&

◆ reverse_iterator

template<typename Type, size_t Size>
using reverse_iterator = typename etl::reverse_iterator<iterator>

◆ size_type

template<typename Type, size_t Size>
using size_type = size_t

◆ value_type

template<typename Type, size_t Size>
using value_type = Type

Member Function Documentation

◆ back() [1/2]

template<typename Type, size_t Size>
auto back ( ) const -> const_reference
inlinenodiscardconstexprnoexcept

Accesses the last item.

◆ back() [2/2]

template<typename Type, size_t Size>
auto back ( ) -> reference
inlinenodiscardconstexprnoexcept

Accesses the last item.

◆ begin() [1/2]

template<typename Type, size_t Size>
auto begin ( ) const -> const_iterator
inlinenodiscardconstexprnoexcept

Returns an iterator to the beginning.

◆ begin() [2/2]

template<typename Type, size_t Size>
auto begin ( ) -> iterator
inlinenodiscardconstexprnoexcept

Returns an iterator to the beginning.

◆ cbegin()

template<typename Type, size_t Size>
auto cbegin ( ) const -> const_iterator
inlinenodiscardconstexprnoexcept

Returns an const iterator to the beginning.

◆ cend()

template<typename Type, size_t Size>
auto cend ( ) const -> const_iterator
inlinenodiscardconstexprnoexcept

Returns an const iterator to the end.

◆ crbegin()

template<typename Type, size_t Size>
auto crbegin ( ) const -> const_reverse_iterator
inlinenodiscardconstexprnoexcept

Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().

◆ crend()

template<typename Type, size_t Size>
auto crend ( ) const -> const_reverse_iterator
inlinenodiscardconstexprnoexcept

Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.

◆ data() [1/2]

template<typename Type, size_t Size>
auto data ( ) const -> const_pointer
inlinenodiscardconstexprnoexcept

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).

◆ data() [2/2]

template<typename Type, size_t Size>
auto data ( ) -> pointer
inlinenodiscardconstexprnoexcept

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).

◆ empty()

template<typename Type, size_t Size>
auto empty ( ) const -> bool
inlinenodiscardconstexprnoexcept

Checks if the container has no elements, i.e. whether begin() == end().

◆ end() [1/2]

template<typename Type, size_t Size>
auto end ( ) const -> const_iterator
inlinenodiscardconstexprnoexcept

Returns an iterator to the end.

◆ end() [2/2]

template<typename Type, size_t Size>
auto end ( ) -> iterator
inlinenodiscardconstexprnoexcept

Returns an iterator to the end.

◆ fill()

template<typename Type, size_t Size>
auto fill ( const_reference value) -> void
inlineconstexpr

Assigns the given value value to all elements in the container.

Examples
array.cpp.

◆ front() [1/2]

template<typename Type, size_t Size>
auto front ( ) const -> const_reference
inlinenodiscardconstexprnoexcept

Accesses the first item.

◆ front() [2/2]

template<typename Type, size_t Size>
auto front ( ) -> reference
inlinenodiscardconstexprnoexcept

Accesses the first item.

◆ max_size()

template<typename Type, size_t Size>
auto max_size ( ) const -> size_type
inlinenodiscardconstexprnoexcept

Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. distance(begin(), end()) for the largest container.

Because each array<T, N> is a fixed-size container, the value returned by max_size equals N (which is also the value returned by size)

◆ operator[]() [1/2]

template<typename Type, size_t Size>
auto operator[] ( size_type const pos) const -> const_reference
inlinenodiscardconstexprnoexcept

Accesses the specified item with range checking.

◆ operator[]() [2/2]

template<typename Type, size_t Size>
auto operator[] ( size_type const pos) -> reference
inlinenodiscardconstexprnoexcept

Accesses the specified item with range checking.

◆ rbegin() [1/2]

template<typename Type, size_t Size>
auto rbegin ( ) const -> const_reverse_iterator
inlinenodiscardconstexprnoexcept

Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().

◆ rbegin() [2/2]

template<typename Type, size_t Size>
auto rbegin ( ) -> reverse_iterator
inlinenodiscardconstexprnoexcept

Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().

◆ rend() [1/2]

template<typename Type, size_t Size>
auto rend ( ) const -> const_reverse_iterator
inlinenodiscardconstexprnoexcept

Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.

◆ rend() [2/2]

template<typename Type, size_t Size>
auto rend ( ) -> reverse_iterator
inlinenodiscardconstexprnoexcept

Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.

◆ size()

template<typename Type, size_t Size>
auto size ( ) const -> size_type
inlinenodiscardconstexprnoexcept

Returns the number of elements in the container, i.e. distance(begin(), end()).

◆ swap()

template<typename Type, size_t Size>
auto swap ( array< Type, Size > & other) -> void
inlineconstexprnoexcept

Exchanges the contents of the container with those of other. Does not cause iterators and references to associate with the other container.

Friends And Related Symbol Documentation

◆ array()

template<typename T, typename... U>
array ( T ,
U...  ) -> array< T, 1+sizeof...(U)>
related

One deduction guide is provided for array to provide an equivalent of experimental::make_array for construction of array from a variadic parameter pack. The program is ill-formed if (is_same_v<T, U> and ...) is not true. Note that it is true when sizeof...(U) is zero.

◆ get() [1/4]

template<size_t Index, typename T, size_t Size>
auto get ( array< T, Size > && array) -> T&&
related

◆ get() [2/4]

template<size_t Index, typename T, size_t Size>
auto get ( array< T, Size > & array) -> T&
related

Extracts the Ith element element from the array. I must be an integer value in range [0, N). This is enforced at compile time as opposed to at() or operator[].

◆ get() [3/4]

template<size_t Index, typename T, size_t Size>
auto get ( array< T, Size > const && array) -> T const&&
related

◆ get() [4/4]

template<size_t Index, typename T, size_t Size>
auto get ( array< T, Size > const & array) -> T const&
related

◆ is_tuple_like< etl::array< T, Size > >

template<typename Type, size_t Size>
template<typename T, etl::size_t Size>
auto is_tuple_like< etl::array< T, Size > > = true
related

◆ operator<

template<typename Type, size_t Size>
auto operator< ( array< Type, Size > const & lhs,
array< Type, Size > const & rhs ) -> bool
friend

Compares the contents of lhs and rhs lexicographically. The comparison is performed by a function equivalent to lexicographical_compare.

◆ operator<=

template<typename Type, size_t Size>
auto operator<= ( array< Type, Size > const & lhs,
array< Type, Size > const & rhs ) -> bool
friend

◆ operator==

template<typename Type, size_t Size>
auto operator== ( array< Type, Size > const & lhs,
array< Type, Size > const & rhs ) -> bool
friend

Checks if the contents of lhs and rhs are equal, that is, they have the same number of elements and each element in lhs compares equal with the element in rhs at the same position.

◆ operator>

template<typename Type, size_t Size>
auto operator> ( array< Type, Size > const & lhs,
array< Type, Size > const & rhs ) -> bool
friend

◆ operator>=

template<typename Type, size_t Size>
auto operator>= ( array< Type, Size > const & lhs,
array< Type, Size > const & rhs ) -> bool
friend

◆ swap

template<typename Type, size_t Size>
auto swap ( array< Type, Size > & lhs,
array< Type, Size > & rhs ) -> void
friend

Specializes the swap algorithm for array. Swaps the contents of lhs and rhs.

◆ to_array() [1/2]

template<typename T, size_t N>
auto to_array ( T(&&) a[N])
related

◆ to_array() [2/2]

template<typename T, size_t N>
auto to_array ( T(&) a[N]) -> array<remove_cv_t<T>, N>
related

Creates a array from the one dimensional built-in array a. The elements of the array are copy-initialized from the corresponding element of a. Copying or moving multidimensional built-in array is not supported.

Member Data Documentation

◆ _buf

template<typename Type, size_t Size>
TETL_NO_UNIQUE_ADDRESS conditional_t<Size == 0, empty_c_array, c_array<Type, Size + size_t{Size == 0}> > _buf

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