UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
create_array.hpp
1
41#ifndef UFO_UTILITY_CREATE_ARRAY_HPP
42#define UFO_UTILITY_CREATE_ARRAY_HPP
43
44// STL
45#include <array>
46#include <utility>
47
48namespace ufo
49{
50// Utility functions for creating std::array filled with a repeated value.
51// Source: https://stackoverflow.com/a/57757301
52
53namespace detail
54{
66template <class T, std::size_t... Is>
67[[nodiscard]] constexpr std::array<T, sizeof...(Is)> createArray(
68 T value, std::index_sequence<Is...>)
69{
70 // cast Is to void to remove the warning: unused value
71 // Each element is initialized to 'value' using parameter pack expansion
72 return {{(static_cast<void>(Is), value)...}};
73}
74} // namespace detail
75
90template <std::size_t N, class T>
91[[nodiscard]] constexpr std::array<T, N> createArray(T const& value)
92{
93 // Calls the helper with an index sequence to expand the value N times
94 return detail::createArray(value, std::make_index_sequence<N>());
95}
96} // namespace ufo
97
98#endif // UFO_UTILITY_CREATE_ARRAY_HPP
All vision-related classes and functions.
Definition cloud.hpp:49
constexpr std::array< T, N > createArray(T const &value)
Creates a std::array of size N, filled with the given value.