const_arrayClass

Template class for a constant array. More...

Public Types

TypeName
Tvalue_type [N]

Public Functions

TypeName
constexprconst_array (typename id< U >::type z)
constexpr Toperator[] (size_t idx) const
constexproperator value_type & () const
voidinitialize () const

Private Properties

TypeName
const_value< T >data_ [N]

Private Functions

TypeName
constexprconst_array (const std::initializer_list< T > &t, const std::index_sequence< Ns... >)
constexpr value_type &fetch_data (const std::index_sequence< Ns... >) const

Detailed Description

The const_array class provides functionality for storing a fixed-size array of elements of type T . This class is designed to be immutable, ensuring that the elements cannot be modified after the array is initialized. It supports initialization from an initializer list and provides access methods for retrieving the elements of the array.

The class is particularly useful in scenarios where a constant array of values is needed, such as for look-up tables, static configurations, or embedded constant data within a program. By leveraging const_value<T> , the class also incorporates additional security mechanisms to prevent tampering or unintended modifications of the stored data.

Template Parameters

  • T: The type of the array elements.

  • N: The size of the array.

Public Types

T value_type [N]

Typedef for the underlying array type.

Definition

typedef T libantispy::const_array< T, N >::value_type[N]

Detailed Description

The value_type typedef defines the type of the underlying array. This is useful for referring to the array type as a whole, especially when passing it around or performing operations that involve the entire array.

Public Functions

constexpr const_array (typename id< U >::type z)

Constructs a const_array object from an initializer list.

Definition

constexpr libantispy::const_array< T, N >::const_array

Detailed Description

This constructor allows the creation of a const_array object using an initializer list. The elements of the initializer list are copied into the internal array. The size of the initializer list should match the size N specified in the template parameter; otherwise, undefined behavior may occur.

Template Parameters

  • U: The type of the initializer list (default is std::initializer_list<T> ).

Parameters

  • z: The initializer list containing the array elements.

constexpr T operator[] (size_t idx) const

Index operator to access array elements.

Definition

constexpr T libantispy::const_array< T, N >::operator[]

Detailed Description

This operator allows access to the elements of the const_array object. The index idx is modulo-sized to ensure it is within the bounds of the array. This prevents out-of-bounds access and ensures safe retrieval of elements.

Parameters

  • idx: The index of the element to access.

Returns

The element at the specified index.

constexpr operator value_type & () const

Conversion operator to the underlying array type.

Definition

constexpr libantispy::const_array< T, N >::operator value_type &

Detailed Description

This conversion operator allows the const_array object to be implicitly converted to a reference to the underlying array type. This can be useful when the entire array is needed, such as for passing it to functions or performing bulk operations on the data.

Returns

A reference to the underlying array.

void initialize () const

Initializes the const_array object.

Definition

void libantispy::const_array< T, N >::initialize

Detailed Description

This method initializes the const_array object by invoking a function at the memory address of the array data. This can be used to set up the array or perform any required initialization steps that depend on the memory location of the data.

Private Properties

const_value< T > data_ [N]

Stores the array elements.

Definition

const_value<T> libantispy::const_array< T, N >::data_[N]

Detailed Description

The data_ array holds the elements of the const_array . Each element is stored as a const_value<T> , which provides additional security and immutability, ensuring that the array cannot be modified after it is created.

Private Functions

constexpr const_array (const std::initializer_list< T > &t, const std::index_sequence< Ns... >)

Constructs a const_array object from an initializer list and index sequence.

Definition

constexpr libantispy::const_array< T, N >::const_array

Detailed Description

This constructor is used internally to initialize the const_array object using an initializer list and an index sequence. The index sequence is used to iterate over the elements of the initializer list and copy them into the internal array.

Parameters

  • t: The initializer list containing the array elements.

Template Parameters

  • Ns: The index sequence for the initializer list.

constexpr value_type & fetch_data (const std::index_sequence< Ns... >) const

Fetches the data of the array.

Definition

constexpr value_type & libantispy::const_array< T, N >::fetch_data

Detailed Description

This method returns a reference to a temporary array containing the elements of the const_array object. It is used to facilitate conversion to the underlying array type.

Template Parameters

  • Ns: The index sequence for the array elements.

Returns

A reference to the temporary array.