KTL
Loading...
Searching...
No Matches
segragator_fwd.h
Go to the documentation of this file.
1#pragma once
2
3#include "reference_fwd.h"
4#include "shared_fwd.h"
5#include "threaded_fwd.h"
7
8#include "../utility/builder.h"
9
10#include <cstddef>
11#include <tuple>
12
13namespace ktl
14{
15 // segragator
16 template<size_t Threshold, typename P, typename F>
17 class segragator;
18
19 namespace detail
20 {
21 // Recursive helper struct for generating the segragator type
22 template<bool, typename>
24
25 // When a single type remains, just return it
26 template<bool R, typename Alloc>
27 struct segragator_builder<R, std::tuple<Alloc>>
28 {
29 using type = Alloc;
30 };
31
32 // Takes in a tuple of types and returns the final segragator
33 template<bool R, typename... Ts>
34 struct segragator_builder<R, std::tuple<Ts...>>
35 {
36 static_assert(sizeof...(Ts) % 2 != 0, "The number of allocators needs to match the number of thresholds + 1");
37
38 // The middle of the parameter pack is the root of a complete binary tree
39 // The root of a complete binary tree is (2^(log2(N)) - 1) / 2
41 (pow2<sizeof...(Ts)>::Result - 1) / 2,
42 sizeof...(Ts) - 1>;
43
44 // Split the parameter pack into 2 tuples
45 using split = tuple_split_indices<1, // Offset by 1, since we don't want the middle
46 std::make_index_sequence<middle::first>, // Up to, but not including the middle threshold
47 std::make_index_sequence<middle::second>, // Anything after the middle threshold
48 std::tuple<Ts...>>;
49
50 // This points to the root of a complete binary tree
51 using threshold = typename std::tuple_element_t<middle::first, std::tuple<Ts...>>;
52
53 // Create this struct recursively for both sides of the middle point
56
58 };
59 }
60
66 template<typename ...Ts>
67 using segragator_builder_min = typename detail::segragator_builder<false, std::tuple<Ts...>>::type;
68
74 template<typename ...Ts>
75 using segragator_builder_max = typename detail::segragator_builder<true, std::tuple<Ts...>>::type;
76
80 template<size_t N>
81 using threshold = std::integral_constant<size_t, N>;
82
86 template<typename T, size_t Threshold, typename P, typename F>
88
92 template<typename T, size_t Threshold, typename P, typename F>
94
98 template<typename T, size_t Threshold, typename P, typename F>
100}
An allocator which delegates allocations between 2 different allocators based on a size threshold.
Definition segragator.h:22
Wrapper class for making an untyped allocator into a typed allocator.
Definition type_allocator.h:21
constexpr bool has_no_value_type_v
Definition meta.h:17
Definition cascading.h:16
typename detail::segragator_builder< true, std::tuple< Ts... > >::type segragator_builder_max
A type builder for a right-leaning segragator allocator.
Definition segragator_fwd.h:75
std::integral_constant< size_t, N > threshold
A shorthand way of writing std::integral_constant<size_t, N>
Definition segragator_fwd.h:81
typename detail::segragator_builder< false, std::tuple< Ts... > >::type segragator_builder_min
A type builder for a left-leaning segragator allocator.
Definition segragator_fwd.h:67
Definition builder.h:12
typename std::tuple_element_t< middle::first, std::tuple< Ts... > > threshold
Definition segragator_fwd.h:51
typename segragator_builder< R, typename split::second >::type second
Definition segragator_fwd.h:55
typename segragator_builder< R, typename split::first >::type first
Definition segragator_fwd.h:54
Definition segragator_fwd.h:23
Definition builder.h:44
Definition builder.h:29