Lodestar
An integrated real-time control package in C++
PairUp.hpp
1 //
2 // Created by Hamza El-Kebir on 6/12/21.
3 //
4 
5 #ifndef LODESTAR_PAIRUP_HPP
6 #define LODESTAR_PAIRUP_HPP
7 
8 #include <tuple>
9 #include <utility>
10 #include <type_traits>
11 #include "Indices.hpp"
12 
13 // See https://stackoverflow.com/a/56367292
14 template <typename ... Nodes>
16 {
17  CollectionImpl(Nodes ... ns) : nodes(ns...){}
18 
19  std::tuple<Nodes...> nodes;
20 };
21 
22 template <typename Seq, typename Tup>
24 
25 template <int ... Is, typename Tuple>
26 struct CollectionMaker<IndexSequence<Is...>, Tuple>
27 {
29  typename std::tuple_element<Is + 1, Tuple>::type>...>;
30 };
31 
32 template <typename ... Ts>
33 using Collection = typename CollectionMaker<typename Indices<sizeof...(Ts) - 1>::type,
34  std::tuple<Ts...>>::type;
35 
36 //template <typename>
37 //struct tag
38 //{ };
39 //
40 //template <typename...>
41 //struct getTpls;
42 //
43 //template <std::size_t ... Is, typename ... Ts>
44 //struct getTpls<IndexSequence<Is...>, Ts...>
45 //{
46 // using tpl0 = std::tuple<tag<Ts>...>;
47 // using ftpl = std::tuple<typename std::tuple_element<Is, tpl0>::type...>;
48 // using stpl = std::tuple<typename std::tuple_element<1u+Is, tpl0>::type...>;
49 //};
50 //
51 //template <typename ... Ts>
52 //struct Collection
53 //{
54 // static_assert( sizeof...(Ts) > 1u, "more types, please");
55 //
56 // using getT = getTpls<typename Indices<sizeof...(Ts)-1u>::type, Ts...>;
57 //
58 // using ftpl = typename getT::ftpl;
59 // using stpl = typename getT::stpl;
60 //
61 // template <typename ... FTs, typename ... STs>
62 // using type = std::tuple<std::pair<FTs, STs>...>;
63 //};
64 
65 //template <typename TInputsList>
66 //struct PairUp{};
67 //
68 //template <typename TInput1, typename TInput2>
69 //struct PairUp<std::tuple<TInput1, TInput2>> {
70 // using type = std::tuple<std::pair<TInput1, TInput2>>;
71 // using pair = std::pair<TInput1, TInput2>;
72 //};
73 //
74 //template <typename TInput1, typename TInput2, typename... TInputs>
75 //struct PairUp<std::tuple<TInput1, TInput2, TInputs...>> {
76 // using type = std::tuple<std::pair<TInput1, TInput2>, PairUp<TInput2, TInputs...>::pair>;
77 // using pair = std::pair<TInput1, TInput2>;
78 //};
79 //
80 //{
81 // typename PairUp<std::tuple<double, int, double>>::type P;
82 //}
83 
84 #endif //LODESTAR_PAIRUP_HPP
Indices
Definition: Indices.hpp:15
CollectionImpl
Definition: PairUp.hpp:15
CollectionMaker
Definition: PairUp.hpp:23
IndexSequence
Definition: Indices.hpp:11