1 #pragma once
2
3 #include <array>
4 #include <tuple>
5 #include <utility>
6
7 namespace sdbusplus
8 {
9
10 namespace utility
11 {
12
13 namespace details
14 {
15
16 /** tuple_to_array - Create std::array from std::tuple.
17 *
18 * @tparam V - Type of the first tuple element.
19 * @tparam Types - Sequence of types for remaining elements, which must
20 * be automatically castable to V.
21 * @tparam I - Sequence of integral indexes (0...N) for each tuple elemeent.
22 *
23 * @param tuple - Tuple of N same-typed elements.
24 * @param @exclude [unnamed] - std::integer_sequence of tuple's index values.
25 *
26 * @return A std::array where each I-th element is tuple's I-th element.
27 */
28 template <typename V, typename... Types, std::size_t... I>
tuple_to_array(std::tuple<V,Types...> && tuple,std::integer_sequence<std::size_t,I...>)29 constexpr auto tuple_to_array(std::tuple<V, Types...>&& tuple,
30 std::integer_sequence<std::size_t, I...>)
31 {
32 return std::array<V, sizeof...(I)>({
33 std::get<I>(tuple)...,
34 });
35 }
36
37 } // namespace details
38
39 /** tuple_to_array - Create std::array from std::tuple.
40 *
41 * @tparam Types - Sequence of types of the tuple elements.
42 * @tparam I - std::integer_sequence of indexes (0..N) for each tuple element.
43 *
44 * @param tuple - Tuple of N same-typed elements.
45 *
46 * @return A std::array where each I-th element is tuple's I-th element.
47 */
48 template <typename... Types,
49 typename I = std::make_index_sequence<sizeof...(Types)>>
tuple_to_array(std::tuple<Types...> && tuple)50 constexpr auto tuple_to_array(std::tuple<Types...>&& tuple)
51 {
52 return details::tuple_to_array(std::move(tuple), I());
53 }
54
55 } // namespace utility
56
57 } // namespace sdbusplus
58