KTL
builder.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstddef>
4 #include <tuple>
5 #include <utility>
6 
7 namespace ktl::detail
8 {
9  // Helper struct for getting the closest power of 2
10  template<size_t N>
11  struct pow2
12  {
13  enum : size_t
14  {
15  A = N - 1,
16  B = A | (A >> 1),
17  C = B | (B >> 2),
18  D = C | (C >> 4),
19  E = D | (D >> 8),
20  F = E | (E >> 16),
21  G = F | (F >> 32),
22  Result = G + 1
23  };
24  };
25 
26 
27  // Helper struct for splitting a tuple based on indices
28  template<size_t, typename, typename, typename>
30 
31  template<size_t O, size_t... N, size_t... M, typename... T>
32  struct tuple_split_indices<O, std::index_sequence<N...>, std::index_sequence<M...>, std::tuple<T...>>
33  {
34  // The middle point is at sizeof...(N)
35  using first = std::tuple<typename std::tuple_element_t<N, std::tuple<T...>>...>;
36 
37  // Offset by N + O, since we don't include the middle type
38  using second = std::tuple<typename std::tuple_element_t<M + O + sizeof...(N), std::tuple<T...>>...>;
39  };
40 
41 
42  // Helper struct for inverting sizes
43  template<bool, size_t, size_t>
44  struct size_invert;
45 
46  template<size_t N, size_t M>
47  struct size_invert<false, N, M>
48  {
49  static constexpr size_t first = N;
50  static constexpr size_t second = M - N;
51  };
52 
53  template<size_t N, size_t M>
54  struct size_invert<true, N, M>
55  {
56  static constexpr size_t first = M - N;
57  static constexpr size_t second = N;
58  };
59 }
Definition: fallback_fwd.h:23
Definition: builder.h:12
@ G
Definition: builder.h:21
@ F
Definition: builder.h:20
@ D
Definition: builder.h:18
@ E
Definition: builder.h:19
@ B
Definition: builder.h:16
@ Result
Definition: builder.h:22
@ A
Definition: builder.h:15
@ C
Definition: builder.h:17
Definition: builder.h:44
std::tuple< typename std::tuple_element_t< N, std::tuple< T... > >... > first
Definition: builder.h:35
std::tuple< typename std::tuple_element_t< M+O+sizeof...(N), std::tuple< T... > >... > second
Definition: builder.h:38
Definition: builder.h:29