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 array_t = conditional_t< Size==0, empty_c_array, c_array< Type, Size+size_t{Size==0}> >
 
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.
 

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
 
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
// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
#include <etl/cassert.hpp>
#if defined(TETL_ENABLE_CXX_MODULES)
import etl;
#else
#include <etl/algorithm.hpp>
#include <etl/array.hpp>
#include <etl/iterator.hpp>
#endif
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:20
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:16
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:19
A container that encapsulates fixed size arrays.
Definition array.hpp:49
The class template bitset represents a fixed-size sequence of Bits bits. Bitsets can be manipulated b...
Definition bitset.hpp:23
Examples
array.cpp, and set.cpp.

Member Typedef Documentation

◆ array_t

◆ const_iterator

◆ const_pointer

◆ const_reference

◆ const_reverse_iterator

◆ difference_type

◆ 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

◆ 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>
constexpr auto back ( ) const -> const_reference
inlineconstexprnoexcept

Accesses the last item.

◆ back() [2/2]

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

Accesses the last item.

◆ begin() [1/2]

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

Returns an iterator to the beginning.

◆ begin() [2/2]

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

Returns an iterator to the beginning.

◆ cbegin()

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

Returns an const iterator to the beginning.

◆ cend()

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

Returns an const iterator to the end.

◆ crbegin()

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

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>
constexpr auto crend ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

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>
constexpr auto data ( ) const -> const_pointer
inlineconstexprnoexcept

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>
constexpr auto data ( ) -> pointer
inlineconstexprnoexcept

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>
constexpr auto empty ( ) const -> bool
inlineconstexprnoexcept

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

◆ end() [1/2]

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

Returns an iterator to the end.

◆ end() [2/2]

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

Returns an iterator to the end.

◆ fill()

template<typename Type , size_t Size>
constexpr 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>
constexpr auto front ( ) const -> const_reference
inlineconstexprnoexcept

Accesses the first item.

◆ front() [2/2]

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

Accesses the first item.

◆ max_size()

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

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>
constexpr auto operator[] ( size_type const  pos) const -> const_reference
inlineconstexprnoexcept

Accesses the specified item with range checking.

◆ operator[]() [2/2]

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

Accesses the specified item with range checking.

◆ rbegin() [1/2]

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

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>
constexpr auto rbegin ( ) -> reverse_iterator
inlineconstexprnoexcept

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>
constexpr auto rend ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

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>
constexpr auto rend ( ) -> reverse_iterator
inlineconstexprnoexcept

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>
constexpr auto size ( ) const -> size_type
inlineconstexprnoexcept

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

◆ swap()

template<typename Type , size_t Size>
constexpr 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>
constexpr auto get ( array< T, Size > &&  array) -> T&&
related

◆ get() [2/4]

template<size_t Index, typename T , size_t Size>
constexpr 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>
constexpr auto get ( array< T, Size > const &&  array) -> T const&&
related

◆ get() [4/4]

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

◆ is_tuple_like()

template<typename T , etl::size_t Size>
constexpr auto is_tuple_like< etl::array< T, Size > >
related

◆ operator<

template<typename Type , size_t Size>
constexpr 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>
constexpr auto operator<= ( array< Type, Size > const lhs,
array< Type, Size > const rhs 
) -> bool
friend

◆ operator==

template<typename Type , size_t Size>
constexpr 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>
constexpr auto operator> ( array< Type, Size > const lhs,
array< Type, Size > const rhs 
) -> bool
friend

◆ operator>=

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

◆ swap

template<typename Type , size_t Size>
constexpr 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>
constexpr auto to_array ( T(&&)  a[N])
related

◆ to_array() [2/2]

template<typename T , size_t N>
constexpr 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.


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