Fcitx
tuplehelpers.h
1 /*
2  * SPDX-FileCopyrightText: 2016-2016 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_UTILS_COMBINETUPLES_H_
8 #define _FCITX_UTILS_COMBINETUPLES_H_
9 
10 #include <tuple>
11 
12 namespace fcitx {
13 
14 template <typename...>
16 
17 template <>
19  using type = std::tuple<>;
20 };
21 
22 template <typename _T1, typename... _Rem>
23 struct CombineTuples<_T1, _Rem...> {
24  using type = typename CombineTuples<std::tuple<_T1>, _Rem...>::type;
25 };
26 
27 template <typename... _Ts>
28 struct CombineTuples<std::tuple<_Ts...>> {
29  using type = std::tuple<_Ts...>;
30 };
31 
32 template <typename... _T1s, typename... _T2s, typename... _Rem>
33 struct CombineTuples<std::tuple<_T1s...>, std::tuple<_T2s...>, _Rem...> {
34  using type =
35  typename CombineTuples<std::tuple<_T1s..., _T2s...>, _Rem...>::type;
36 };
37 
38 template <typename... Args>
39 using CombineTuplesType = typename CombineTuples<Args...>::type;
40 
41 template <int...>
42 struct Sequence {};
43 
44 template <int N, int... S>
45 struct MakeSequence : MakeSequence<N - 1, N - 1, S...> {};
46 
47 template <int... S>
48 struct MakeSequence<0, S...> {
49  using type = Sequence<S...>;
50 };
51 
52 template <typename... Args, typename F, int... S>
53 auto callWithIndices(const F &func, Sequence<S...> /*unused*/,
54  std::tuple<Args...> &tuple) {
55  return func(std::get<S>(tuple)...);
56 }
57 
58 template <typename... Args, typename F>
59 auto callWithTuple(F func, std::tuple<Args...> &tuple) {
60  typename MakeSequence<sizeof...(Args)>::type a;
61  return callWithIndices(func, a, tuple);
62 }
63 } // namespace fcitx
64 
65 #endif // _FCITX_UTILS_COMBINETUPLES_H_
Definition: action.cpp:17
Definition: matchrule.h:78