tenno 0.1.0
Loading...
Searching...
No Matches
tenno::array< T, N > Class Template Reference

A fixed-size array. More...

#include <array.hpp>

Data Structures

struct  const_iterator
 A const iterator to iterate over the array. More...
 
struct  const_reverse_iterator
 A const iterator to iterate over the array. More...
 
struct  iterator
 An iterator to iterate over the array. More...
 
struct  reverse_iterator
 A reverse iterator over the array. More...
 

Public Types

using value_type = T
 The type of the elements in the array.
 

Public Member Functions

constexpr array ()
 Construct a new array object.
 
constexpr array (std::initializer_list< T > list)
 Construct a new array object with a list of elements.
 
constexpr array (const array &other)
 
constexpr tenno::size size () const noexcept
 Get the size of the array.
 
constexpr tenno::expected< T, tenno::errorat (const tenno::size index) const noexcept
 Access an element of the array.
 
constexpr T front () const noexcept
 Access an element of the array.
 
constexpr T back () const noexcept
 Access an element of the array.
 
T * data () noexcept
 Access an element of the array.
 
constexpr const T * data () const noexcept
 Access the underlying data of the array.
 
constexpr bool empty () const noexcept
 Check if the array is empty.
 
constexpr tenno::size max_size () const noexcept
 Get the maximum size of the array.
 
void fill (const T &value) noexcept
 Fill the array with a value.
 
void swap (array &other) noexcept
 Swap the contents of the array with another array.
 
constexpr T & operator[] (const tenno::size index) noexcept
 Access an element of the array.
 
constexpr const T & operator[] (const tenno::size index) const noexcept
 Access an element of the array constexpr.
 
constexpr arrayoperator= (const array &other) noexcept
 
iterator begin () noexcept
 Get an iterator to the beginning of the array.
 
iterator end () noexcept
 Get an iterator to the end of the array.
 
constexpr const_iterator cbegin () const noexcept
 Get an const_iterator to the beginning of the array.
 
constexpr const_iterator cend () const noexcept
 Get an const_iterator to the end of the array.
 
reverse_iterator rbegin () noexcept
 Get an reverse_iterator to the beginning of the array.
 
reverse_iterator rend () noexcept
 Get an reverse_iterator to the end of the array.
 
constexpr const_reverse_iterator crbegin () const noexcept
 Get an const_reverse_iterator to the beginning of the array.
 
constexpr const_reverse_iterator crend () const noexcept
 Get an const_reverse_iterator to the end of the array.
 

Static Public Member Functions

static constexpr T generate_default ()
 
static constexpr tenno::array< T, N > init () noexcept
 Initialize all elements of the array to the default value of T.
 

Detailed Description

template<typename T, tenno::size N>
class tenno::array< T, N >

A fixed-size array.

Template Parameters
TThe type of the elements in the array
NThe size of the array

Example

auto arr = tenno::array<int, 5>();
A fixed-size array.
Definition array.hpp:33

No memory allocation is performed, and the array is stored on the stack.

Definition at line 32 of file array.hpp.

Member Typedef Documentation

◆ value_type

template<typename T , tenno::size N>
using tenno::array< T, N >::value_type = T

The type of the elements in the array.

Definition at line 38 of file array.hpp.

Constructor & Destructor Documentation

◆ array() [1/3]

template<typename T , tenno::size N>
tenno::array< T, N >::array ( )
inlineconstexpr

Construct a new array object.

By default, the array's elements are not initialized for performance reasons. If you want to initialize the array's elements, use the static init method.

Definition at line 53 of file array.hpp.

◆ array() [2/3]

template<typename T , tenno::size N>
tenno::array< T, N >::array ( std::initializer_list< T > list)
inlineconstexpr

Construct a new array object with a list of elements.

Parameters
listThe list of elements to initialize the array with

Example

tenno::array<int, 5> arr{1, 2, 3, 4, 5};
tenno::array<int, 5> arr2 = {5, 4, 3, 2, 1};

Definition at line 72 of file array.hpp.

◆ array() [3/3]

template<typename T , tenno::size N>
tenno::array< T, N >::array ( const array< T, N > & other)
inlineconstexpr

Definition at line 77 of file array.hpp.

Member Function Documentation

◆ at()

template<typename T , tenno::size N>
tenno::expected< T, tenno::error > tenno::array< T, N >::at ( const tenno::size index) const
inlineconstexprnoexcept

Access an element of the array.

Parameters
indexThe index of the element to access
Returns
tenno::expected<T, tenno::error> The element at the index

Example

auto arr = tenno::array<int, 5>{1, 2, 3, 4, 5};
auto elem = arr.at(2);
if (elem.has_value())
{
std::cout << elem.value() << std::endl;
}
constexpr tenno::expected< T, tenno::error > at(const tenno::size index) const noexcept
Access an element of the array.
Definition array.hpp:133

Definition at line 133 of file array.hpp.

◆ back()

template<typename T , tenno::size N>
T tenno::array< T, N >::back ( ) const
inlineconstexprnoexcept

Access an element of the array.

Parameters
indexThe index of the element to access
Returns
T The element at the index

Example

auto arr = tenno::array<int, 5>{1, 2, 3, 4, 5};
auto elem = arr[2];

Definition at line 171 of file array.hpp.

◆ begin()

template<typename T , tenno::size N>
iterator tenno::array< T, N >::begin ( )
inlinenoexcept

Get an iterator to the beginning of the array.

Returns
iterator The iterator to the beginning of the array

Example

auto arr = tenno::array<int, 5>();
auto begin = arr.begin();
iterator begin() noexcept
Get an iterator to the beginning of the array.
Definition array.hpp:367

Definition at line 367 of file array.hpp.

◆ cbegin()

template<typename T , tenno::size N>
const_iterator tenno::array< T, N >::cbegin ( ) const
inlineconstexprnoexcept

Get an const_iterator to the beginning of the array.

Returns
const_iterator The iterator to the beginning of the array

Example

auto arr = tenno::array<int, 5>();
auto begin = arr.begin();

Definition at line 446 of file array.hpp.

◆ cend()

template<typename T , tenno::size N>
const_iterator tenno::array< T, N >::cend ( ) const
inlineconstexprnoexcept

Get an const_iterator to the end of the array.

Returns
const_iterator The iterator to the end of the array

Example

tenno::for_each(arr.begin(), arr.end(), [](int& elem) { elem = 0; });
constexpr UnaryFunc for_each(InputIt first, InputIt last, UnaryFunc f)
Applies the given function f to the result of dereferencing every element in the range [first,...
Definition algorithm.hpp:56

Definition at line 460 of file array.hpp.

◆ crbegin()

template<typename T , tenno::size N>
const_reverse_iterator tenno::array< T, N >::crbegin ( ) const
inlineconstexprnoexcept

Get an const_reverse_iterator to the beginning of the array.

Returns
const_reverse_iterator The iterator to the beginning of the array

Example

auto arr = tenno::array<int, 5>();
auto begin = arr.begin();

Definition at line 606 of file array.hpp.

◆ crend()

template<typename T , tenno::size N>
const_reverse_iterator tenno::array< T, N >::crend ( ) const
inlineconstexprnoexcept

Get an const_reverse_iterator to the end of the array.

Returns
const_reverse_iterator The iterator to the end of the array

Example

tenno::for_each(arr.begin(), arr.end(), [](int& elem) { elem = 0; });

Definition at line 620 of file array.hpp.

◆ data() [1/2]

template<typename T , tenno::size N>
const T * tenno::array< T, N >::data ( ) const
inlineconstexprnoexcept

Access the underlying data of the array.

Returns
const T* The underlying data of the array

Definition at line 197 of file array.hpp.

◆ data() [2/2]

template<typename T , tenno::size N>
T * tenno::array< T, N >::data ( )
inlinenoexcept

Access an element of the array.

Parameters
indexThe index of the element to access
Returns
T The element at the index

Example

auto arr = tenno::array<int, 5>{1, 2, 3, 4, 5};
auto elem = arr[2];

Definition at line 188 of file array.hpp.

◆ empty()

template<typename T , tenno::size N>
bool tenno::array< T, N >::empty ( ) const
inlineconstexprnoexcept

Check if the array is empty.

Returns
true If the array is empty
false If the array is not empty

Example

auto arr = tenno::array<int, 5>();
if (arr.empty())
{
std::cout << "The array is empty" << std::endl;
}

Definition at line 217 of file array.hpp.

◆ end()

template<typename T , tenno::size N>
iterator tenno::array< T, N >::end ( )
inlinenoexcept

Get an iterator to the end of the array.

Returns
iterator The iterator to the end of the array

Example

tenno::for_each(arr.begin(), arr.end(), [](int& elem) { elem = 0; });

Definition at line 381 of file array.hpp.

◆ fill()

template<typename T , tenno::size N>
void tenno::array< T, N >::fill ( const T & value)
inlinenoexcept

Fill the array with a value.

Parameters
valueThe value to fill the array with

Example

auto arr = tenno::array<int, 5>();
arr.fill(0);

Definition at line 249 of file array.hpp.

◆ front()

template<typename T , tenno::size N>
T tenno::array< T, N >::front ( ) const
inlineconstexprnoexcept

Access an element of the array.

Parameters
indexThe index of the element to access
Returns
T The element at the index

Example

auto arr = tenno::array<int, 5>{1, 2, 3, 4, 5};
auto elem = arr[2];

Definition at line 154 of file array.hpp.

◆ generate_default()

template<typename T , tenno::size N>
static constexpr T tenno::array< T, N >::generate_default ( )
inlinestaticconstexpr

Definition at line 41 of file array.hpp.

◆ init()

template<typename T , tenno::size N>
static constexpr tenno::array< T, N > tenno::array< T, N >::init ( )
inlinestaticconstexprnoexcept

Initialize all elements of the array to the default value of T.

Example

static constexpr tenno::array< T, N > init() noexcept
Initialize all elements of the array to the default value of T.
Definition array.hpp:106

Definition at line 106 of file array.hpp.

◆ max_size()

template<typename T , tenno::size N>
tenno::size tenno::array< T, N >::max_size ( ) const
inlineconstexprnoexcept

Get the maximum size of the array.

Returns
tenno::size The maximum size of the array

Example

auto arr = tenno::array<int, 5>();
const tenno::size max_size = arr.max_size();
constexpr tenno::size max_size() const noexcept
Get the maximum size of the array.
Definition array.hpp:233
size_t size
Definition types.hpp:13

Definition at line 233 of file array.hpp.

◆ operator=()

template<typename T , tenno::size N>
array & tenno::array< T, N >::operator= ( const array< T, N > & other)
inlineconstexprnoexcept

Definition at line 302 of file array.hpp.

◆ operator[]() [1/2]

template<typename T , tenno::size N>
const T & tenno::array< T, N >::operator[] ( const tenno::size index) const
inlineconstexprnoexcept

Access an element of the array constexpr.

Definition at line 297 of file array.hpp.

◆ operator[]() [2/2]

template<typename T , tenno::size N>
T & tenno::array< T, N >::operator[] ( const tenno::size index)
inlineconstexprnoexcept

Access an element of the array.

Parameters
indexThe index of the element to access
Returns
T The element at the index

Example

auto arr = tenno::array<int, 5>{1, 2, 3, 4, 5};
auto elem = arr[2];

Definition at line 289 of file array.hpp.

◆ rbegin()

template<typename T , tenno::size N>
reverse_iterator tenno::array< T, N >::rbegin ( )
inlinenoexcept

Get an reverse_iterator to the beginning of the array.

Returns
reverse_iterator The reverse_iterator to the beginning of the array

Example

auto arr = tenno::array<int, 5>();
auto begin = arr.begin();

Definition at line 525 of file array.hpp.

◆ rend()

template<typename T , tenno::size N>
reverse_iterator tenno::array< T, N >::rend ( )
inlinenoexcept

Get an reverse_iterator to the end of the array.

Returns
reverse_iterator The reverse_iterator to the end of the array

Example

tenno::for_each(arr.begin(), arr.end(), [](int& elem) { elem = 0; });

Definition at line 539 of file array.hpp.

◆ size()

template<typename T , tenno::size N>
tenno::size tenno::array< T, N >::size ( ) const
inlineconstexprnoexcept

Get the size of the array.

Returns
tenno::size The size of the array

Example

auto arr = tenno::array<int, 5>();
const tenno::size size = arr.size();

Definition at line 93 of file array.hpp.

◆ swap()

template<typename T , tenno::size N>
void tenno::array< T, N >::swap ( array< T, N > & other)
inlinenoexcept

Swap the contents of the array with another array.

Parameters
otherThe other array to swap with

Example

auto arr = tenno::array<int, 3>{1, 2, 3};
auto arr2 = tenno::array<int, 3>{4, 5, 6};
arr.swap(arr2);
void swap(array &other) noexcept
Swap the contents of the array with another array.
Definition array.hpp:267

Definition at line 267 of file array.hpp.


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