Array Utilities

Header: fiction/utils/stl/array_utils.hpp

template<std::size_t N, typename T>
constexpr auto fiction::utils::stl::create_array(const T &value)

Creates an array of size N and initializes its fields with value of type T at compile time.

Template Parameters:
  • N – Array size.

  • T – Type of array.

Parameters:

value – Initial value to each field.

Returns:

An object of type std::array<T, N> that is initialized with N copies of value.

template<typename ElementType, typename T, std::size_t N>
constexpr auto fiction::utils::stl::convert_array(const std::array<T, N> &a)

Converts an array of size N and type T to an array of size N and type ElementType by applying static_cast at compile time.

Template Parameters:
  • ElementType – New type of each element in the returned array.

  • T – Element type of the input array.

  • N – Size of both the input and the output array.

Parameters:

a – The array to be converted.

Returns:

An object of type std::array<ElementType, N> that was created by casting each element in a to ElementType.

template<typename ElementType, typename T, std::size_t N, std::size_t M>
constexpr auto fiction::utils::stl::convert_array_of_arrays(const std::array<std::array<T, M>, N> &a)

Same as convert_array but for 2D arrays.

Template Parameters:
  • ElementType – New type of each element in the returned array.

  • T – Element type of the input array.

  • N – Outer size of both the input and the output array.

  • M – Inner size of both the input and the output array.

Parameters:

a – The array to be converted.

Returns:

An object of type std::array<std::array<ElementType, M>, N> that was created by casting each element in a to ElementType using static_cast.