0.2.0
Loading...
Searching...
No Matches
Array.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <array>
17
18#include "util/Assert.h"
19
20namespace NAV
21{
22
23namespace detail
24{
25
28template<typename T, std::size_t... Is>
29constexpr std::array<T, sizeof...(Is)> create_array(const T& value, std::index_sequence<Is...> /* unused */)
30{
31 // cast Is to void to remove the warning: unused value
32 return { { (static_cast<void>(Is), value)... } };
33}
34
35} // namespace detail
36
40template<std::size_t N, typename T>
41constexpr std::array<T, N> create_array(const T& value)
42{
43 return detail::create_array(value, std::make_index_sequence<N>());
44}
45
50template<size_t N, typename Scalar>
51constexpr std::array<Scalar, N> genRangeArray(Scalar start, Scalar stepSize, [[maybe_unused]] Scalar end)
52{
53 std::array<Scalar, N> container{};
54
55 for (size_t i = 0; i < container.size(); i++)
56 {
57 container.at(i) = start;
58 INS_ASSERT_USER_ERROR(start < end, "The range exceeds the end value.");
59 start += stepSize;
60 }
61
62 INS_ASSERT_USER_ERROR(start + stepSize > end, "The end value exceeds the range.");
63
64 return container;
65};
66
67} // namespace NAV
constexpr std::array< T, sizeof...(Is)> create_array(const T &value, std::index_sequence< Is... >)
Create an array with the value assigned to all elements in the container.
Definition Array.hpp:29
constexpr std::array< Scalar, N > genRangeArray(Scalar start, Scalar stepSize, Scalar end)
Returns a container filled with the given range.
Definition Array.hpp:51
Assertion helpers.
#define INS_ASSERT_USER_ERROR(_EXP, _MSG)
Assert function with message.
Definition Assert.h:21