Repository navigation
Expand file tree
/
Copy pathallocator_info.hpp
More file actions
80 lines (62 loc) · 1.85 KB
/
Copy pathallocator_info.hpp
File metadata and controls
80 lines (62 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include <type_traits>
#include <concepts>
#include <compare>
#include <cassert>
#include <utility>
#include "concept_extras.hpp"
namespace compile_time::allocator{
template<typename T>
struct single_info{
std::size_t current_amount = 0;
std::size_t high_water_mark = 0;
constexpr single_info& single(){
return *this;
}
constexpr single_info(int i):high_water_mark(i){}
constexpr const single_info& single() const {
return *this;
}
constexpr single_info() = default;
constexpr single_info(single_info&&) = default;
constexpr void advance_to(const single_info &i){
current_amount = i.current_amount;
high_water_mark = i.high_water_mark;
}
protected:
constexpr single_info(const single_info&) = default;
};
template<typename... T>
struct Info : public single_info<T>... {
template<PackMember<T...> U>
constexpr std::size_t max() const {
return single_info<U>::single().high_water_mark;
}
template<PackMember<T...> U>
constexpr const auto& single() const {
return single_info<U>::single();
}
template<PackMember<T...> U>
constexpr auto& single() {
return single_info<U>::single();
}
constexpr std::size_t maxes() const {
return ((single<T>().high_water_mark) + ...);
}
constexpr void advance_to(const Info& i) {
(single_info<T>::advance_to(i),...);
}
template<PackMember<T...> U> constexpr void advance_to(const single_info<U> &i){
single_info<U>::advance_to(i);
}
static constexpr Info set_all_to_constant(std::size_t i){
Info inf;
((inf.template single<T>().current_amount = i),...);
((inf.template single<T>().high_water_mark = i),...);
return inf;
}
constexpr Info() = default;
constexpr Info(Info&&) = default;
constexpr Info(const Info&) = default;
};
}