Template Numerical Library: TNL::Containers::StaticArray< Size, Value > Class Template Reference

Template Numerical Library version\ main:16b9213d5

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
TNL::Containers::StaticArray< Size, Value > Class Template Reference

Array with constant size. More...

`#include <TNL/Containers/StaticArray.h>`

Inheritance diagram for TNL::Containers::StaticArray< Size, Value >:
[legend]
Collaboration diagram for TNL::Containers::StaticArray< Size, Value >:
[legend]

## Public Types
using | IndexType = int
| Type being used for the array elements indexing.
using | ValueType = Value
| Type of elements stored in this array.

## Public Member Functions
__cuda_callable__ constexpr | StaticArray ()=default
| Default constructor.
__cuda_callable__ constexpr | StaticArray (const StaticArray &v)
| Copy constructor.
template<typename OtherValue>
__cuda_callable__ constexpr | StaticArray (const StaticArray< Size, OtherValue > &v)
| Templated copy constructor.
template<typename OtherValue>
__cuda_callable__ constexpr | StaticArray (const std::array< OtherValue, Size > &array)
| Constructor which initializes the array by copying elements from std::array.
template<typename OtherValue, std::enable_if_t< std::is_convertible_v< OtherValue, ValueType >, bool > = true>
__cuda_callable__ constexpr | StaticArray (const std::initializer_list< OtherValue > &elems)
| Constructor which initializes the array by copying elements from std::initializer_list, e.g. {...}.
template<typename T, std::enable_if_t< std::is_same_v< T, int > &&! std::is_same_v< T, Value >, bool > = true>
__cuda_callable__ constexpr | StaticArray (const T &v)
| Constructor that sets all array components to value v.
__cuda_callable__ constexpr | StaticArray (const Value &v)
| Constructor that sets all array components to value v.
template<typename _unused = void>
__cuda_callable__ constexpr | StaticArray (const Value v[Size])
| Constructor from static array.
constexpr | StaticArray (StaticArray &&) noexcept=default
| Move constructor.
__cuda_callable__ constexpr | StaticArray (std::array< Value, Size > &&array)
| Constructor which initializes the array by moving elements from std::array.
template<typename... Values, std::enable_if_t<(Size > 1) &&sizeof...(Values)==Size, bool > = true>
__cuda_callable__ constexpr | StaticArray (Values &&... values)
| Constructor which initializes the array element-by-element using the supplied values.
constexpr const Value * | getData () const noexcept
| Gets constant pointer to data of this static array.
constexpr Value * | getData () noexcept
| Gets pointer to data of this static array.
constexpr Value | getElement (IndexType i) const noexcept
| Returns the value of the i-th element.
void | load (File &file)
| Loads data from the file to this static array.
template<typename Array>
constexpr bool | operator!= (const Array &array) const
| This function checks whether this static array is not equal to another array.
constexpr const Value & | operator() (int i) const noexcept
| Accesses specified element at the position i and returns a constant reference to its value.
constexpr Value & | operator() (int i) noexcept
| Accesses specified element at the position i and returns a reference to its value.
constexpr StaticArray & | operator= (const StaticArray &v)
| Copy-assignment operator.
template<typename T, typename..., typename = std::enable_if_t< std::is_convertible_v< T, ValueType > || IsStaticArrayType< T >::value >>
constexpr StaticArray< Size, Value > & | operator= (const T &v)
| Assigns an object v of type T.
constexpr StaticArray & | operator= (StaticArray &&) noexcept=default
| Move-assignment operator.
template<typename Array>
constexpr bool | operator== (const Array &array) const
| This function checks whether this static array is equal to another array.
constexpr const Value & | operator[] (int i) const noexcept
| Accesses specified element at the position i and returns a constant reference to its value.
constexpr Value & | operator[] (int i) noexcept
| Accesses specified element at the position i and returns a reference to its value.
void | save (File &file) const
| Saves this static array into the file.
constexpr void | setElement (IndexType i, ValueType value) noexcept
| Sets the value of the i-th element to value.
constexpr void | setValue (const ValueType &val)
| Sets all values of this static array to val.
constexpr void | sort ()
| Sorts the elements in this static array in ascending order.
std::ostream & | write (std::ostream &str, const char *separator=" ") const
| Writes the array values into stream str with specified separator.
constexpr const Value & | x () const noexcept
| Returns constant reference to the first coordinate.
constexpr Value & | x () noexcept
| Returns reference to the first coordinate.
constexpr const Value & | y () const noexcept
| Returns constant reference to the second coordinate for arrays with Size >= 2.
constexpr Value & | y () noexcept
| Returns reference to the second coordinate for arrays with Size >= 2.
constexpr const Value & | z () const noexcept
| Returns constant reference to the third coordinate for arrays with Size >= 3.
constexpr Value & | z () noexcept
| Returns reference to the third coordinate for arrays with Size >= 3.

## Static Public Member Functions
static constexpr int | getSize ()
| Gets size of this array.

## Protected Attributes
std::array< Value, Size > | data

## Detailed Description

template<int Size, typename Value>
class TNL::Containers::StaticArray< Size, Value >

Array with constant size.

Template Parameters

  Size | Size of static array. Number of its elements.
  Value | Type of the values in static array.

## Constructor & Destructor Documentation

## ◆ StaticArray() [1/9]

template<int Size, typename Value>
template<typename T, std::enable_if_t< std::is_same_v< T, int > &&! std::is_same_v< T, Value >, bool > = true>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | const T & | v | ) |
| constexpr

Constructor that sets all array components to value v.

Parameters

  v | Reference to a value.

## ◆ StaticArray() [2/9]

template<int Size, typename Value>
template<typename _unused = void>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | const Value | v[Size] | ) |
| constexpr

Constructor from static array.

Parameters

  v | Input array.

## ◆ StaticArray() [3/9]

template<int Size, typename Value>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | const Value & | v | ) |
| constexpr

Constructor that sets all array components to value v.

Parameters

  v | Reference to a value.

## ◆ StaticArray() [4/9]

template<int Size, typename Value>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | const StaticArray< Size, Value > & | v | ) |
| constexpr

Copy constructor.

Constructs a copy of another static array v.

## ◆ StaticArray() [5/9]

template<int Size, typename Value>
template<typename OtherValue>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | const StaticArray< Size, OtherValue > & | v | ) |
| constexpr

Templated copy constructor.

Constructs a copy of another static array v where the value type is ValueType. This constructor allows casting between StaticArray types with the same size, but different value types.

## ◆ StaticArray() [6/9]

template<int Size, typename Value>
template<typename... Values, std::enable_if_t<(Size > 1) &&sizeof...(Values)==Size, bool > = true>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | Values &&... | values | ) |
| constexpr

Constructor which initializes the array element-by-element using the supplied values.

It behaves like the aggregate-initialization in std::array, e.g. StaticArray< 3, int > a = {1, 2, 3};. The number of supplied arguments must be equal to Size.

Parameters

  values | The elements forwarded to the constructor of the underlying std::array.

## ◆ StaticArray() [7/9]

template<int Size, typename Value>
template<typename OtherValue, std::enable_if_t< std::is_convertible_v< OtherValue, ValueType >, bool > = true>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | const std::initializer_list< OtherValue > & | elems | ) |
| constexpr

Constructor which initializes the array by copying elements from std::initializer_list, e.g. {...}.

The initializer list size must larger or equal to Size.

Parameters

  elems | input initializer list

## ◆ StaticArray() [8/9]

template<int Size, typename Value>
template<typename OtherValue>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | const std::array< OtherValue, Size > & | array | ) |
| constexpr

Constructor which initializes the array by copying elements from std::array.

Parameters

  array | input array

## ◆ StaticArray() [9/9]

template<int Size, typename Value>

__cuda_callable__ constexpr TNL::Containers::StaticArray< Size, Value >::StaticArray | ( | std::array< Value, Size > && | array | ) |
| constexpr

Constructor which initializes the array by moving elements from std::array.

Parameters

  array | input array

## Member Function Documentation

## ◆ getElement()

template<int Size, typename Value>

Value TNL::Containers::StaticArray< Size, Value >::getElement | ( | IndexType | i | ) | const
| nodiscardconstexprnoexcept

Returns the value of the i-th element.

Parameters

  i | The index of the element to be returned.

## ◆ load()

template<int Size, typename Value>

void TNL::Containers::StaticArray< Size, Value >::load | ( | File & | file | ) |

Loads data from the file to this static array.

Parameters

  file | Reference to a file.

## ◆ operator!=()

template<int Size, typename Value>
template<typename Array>

bool TNL::Containers::StaticArray< Size, Value >::operator!= | ( | const Array & | array | ) | const
| nodiscardconstexpr

This function checks whether this static array is not equal to another array.

Return true if the arrays are not equal in size. Otherwise returns false.

## ◆ operator()() [1/2]

template<int Size, typename Value>

const Value & TNL::Containers::StaticArray< Size, Value >::operator() | ( | int | i | ) | const
| nodiscardconstexprnoexcept

Accesses specified element at the position i and returns a constant reference to its value.

Equivalent to operator[].

## ◆ operator()() [2/2]

template<int Size, typename Value>

Value & TNL::Containers::StaticArray< Size, Value >::operator() | ( | int | i | ) |
| nodiscardconstexprnoexcept

Accesses specified element at the position i and returns a reference to its value.

Equivalent to operator[].

## ◆ operator=()

template<int Size, typename Value>
template<typename T, typename..., typename = std::enable_if_t< std::is_convertible_v< T, ValueType > || IsStaticArrayType< T >::value >>

StaticArray< Size, Value > & TNL::Containers::StaticArray< Size, Value >::operator= | ( | const T & | v | ) |
| constexpr

Assigns an object v of type T.

T can be:

1. Static linear container implementing operator[] and having the same size. In this case, v is copied to this array elementwise.
2. An object that can be converted to Value type. In this case all elements are set to v.

## ◆ operator==()

template<int Size, typename Value>
template<typename Array>

bool TNL::Containers::StaticArray< Size, Value >::operator== | ( | const Array & | array | ) | const
| nodiscardconstexpr

This function checks whether this static array is equal to another array.

Return true if the arrays are equal in size. Otherwise returns false.

## ◆ operator[]() [1/2]

template<int Size, typename Value>

const Value & TNL::Containers::StaticArray< Size, Value >::operator[] | ( | int | i | ) | const
| nodiscardconstexprnoexcept

Accesses specified element at the position i and returns a constant reference to its value.

Parameters

  i | Index position of an element.

## ◆ operator[]() [2/2]

template<int Size, typename Value>

Value & TNL::Containers::StaticArray< Size, Value >::operator[] | ( | int | i | ) |
| nodiscardconstexprnoexcept

Accesses specified element at the position i and returns a reference to its value.

Parameters

  i | Index position of an element.

## ◆ save()

template<int Size, typename Value>

void TNL::Containers::StaticArray< Size, Value >::save | ( | File & | file | ) | const

Saves this static array into the file.

Parameters

  file | Reference to a file.

## ◆ setElement()

template<int Size, typename Value>

void TNL::Containers::StaticArray< Size, Value >::setElement | ( | IndexType | i,
|  | ValueType | value )
| constexprnoexcept

Sets the value of the i-th element to value.

Parameters

  i | The index of the element to be set.
  value | The new value of the element.

## ◆ write()

template<int Size, typename Value>

std::ostream & TNL::Containers::StaticArray< Size, Value >::write | ( | std::ostream & | str,
|  | const char * | separator = " " ) const

Writes the array values into stream str with specified separator.

Parameters

  str | Reference to a stream.
  separator | Character separating the array values in the stream str. Is set to " " by default.

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

- src/TNL/Containers/StaticArray.h