KTL
fallback_fwd.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "shared_fwd.h"
4 #include "threaded_fwd.h"
5 #include "type_allocator_fwd.h"
6 
7 #include "../utility/builder.h"
8 
9 #include <cstddef>
10 #include <tuple>
11 
12 namespace ktl
13 {
14  // type_allocator
15  template<typename T, typename Alloc>
16  class type_allocator;
17 
18  // fallback
19  template<typename P, typename F>
20  class fallback;
21 
22  namespace detail
23  {
24  // Recursive helper struct for generating the segragator type
25  template<bool, typename>
27 
28  // When a single type remains, just return it
29  template<bool R, typename Alloc>
30  struct fallback_builder<R, std::tuple<Alloc>>
31  {
32  using type = Alloc;
33  };
34 
35  // Takes in a tuple of types and returns the final fallback
36  template<bool R, typename... Ts>
37  struct fallback_builder<R, std::tuple<Ts...>>
38  {
39  // The middle of the parameter pack is the root of a complete binary tree
40  // The pack can be split in 2 using 2^(log2(N)) / 2
41  using middle = size_invert<R,
42  pow2<sizeof...(Ts)>::Result / 2,
43  sizeof...(Ts)>;
44 
45  // Split the parameter pack into 2 tuples
46  using split = tuple_split_indices<0, // No offset
47  std::make_index_sequence<middle::first>, // One half, up to the middle point
48  std::make_index_sequence<middle::second>, // Anything after the middle threshold
49  std::tuple<Ts...>>;
50 
51  // Create this struct recursively for both sides of the middle point
54 
56  };
57  }
58 
63  template<typename... Ts>
64  using fallback_builder_min = typename detail::fallback_builder<false, std::tuple<Ts...>>::type;
65 
70  template<typename... Ts>
71  using fallback_builder_max = typename detail::fallback_builder<true, std::tuple<Ts...>>::type;
72 
76  template<typename T, typename P, typename F>
78 
82  template<typename T, typename P, typename F>
84 }
An allocator which delegates allocations between 2 different allocators. It first attempts to allocat...
Definition: fallback.h:23
Wrapper class for making an untyped allocator into a typed allocator.
Definition: type_allocator.h:20
Definition: cascading.h:15
typename detail::fallback_builder< false, std::tuple< Ts... > >::type fallback_builder_min
A type builder for a left-leaning fallback allocator.
Definition: fallback_fwd.h:64
typename detail::fallback_builder< true, std::tuple< Ts... > >::type fallback_builder_max
A type builder for a right-leaning fallback allocator.
Definition: fallback_fwd.h:71
typename fallback_builder< R, typename split::first >::type first
Definition: fallback_fwd.h:52
typename fallback_builder< R, typename split::second >::type second
Definition: fallback_fwd.h:53
Definition: fallback_fwd.h:26
Definition: builder.h:12
Definition: builder.h:44
Definition: builder.h:29