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
Nand initializes its fields with value of typeTat 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 withNcopies 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
Nand typeTto an array of sizeNand typeElementTypeby applyingstatic_castat 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 inatoElementType.
-
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_arraybut 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 inatoElementTypeusingstatic_cast.