EmrysFilter 0.1.0
State estimation utilities in C++23 using Eigen
Loading...
Searching...
No Matches
Allocation.h
Go to the documentation of this file.
1#pragma once
2
8
9#include <cstddef>
10#include <memory>
11#include <optional>
12#include <utility>
13#include <vector>
14
16
17namespace Emrys
18{
19
43
47using DefaultAllocator = std::allocator<std::byte>;
48
54{
55 Eigen::Index count;
56};
57
58namespace internal
59{
60
62template <typename Allocator, typename T>
63using ReBound = typename std::allocator_traits<Allocator>::template rebind_alloc<T>;
64
74template <typename T, typename Allocator>
75class Buffer : public std::vector<T, ReBound<Allocator, T>>
76{
77public:
78
79 using Base = std::vector<T, ReBound<Allocator, T>>;
80 using Base::Base;
81
82 Buffer() = default;
83
87 Buffer(Base const & vector)
88 : Base(vector, vector.get_allocator())
89 {}
90
92 Buffer(Base && vector) noexcept
93 : Base(std::move(vector))
94 {}
95
97 Buffer(Buffer const & other)
98 : Buffer(other, other.get_allocator())
99 {}
100
102 Buffer(Buffer const & other, typename Base::allocator_type const & allocator)
103 : Base(allocator)
104 {
105 this->reserve(other.capacity());
106 this->assign(other.begin(), other.end());
107 }
108
109 Buffer(Buffer &&) noexcept = default;
110
112 Buffer &
113 operator=(Buffer const &) = default;
114
116 Buffer &
117 operator=(Buffer &&) = default;
118
119 ~Buffer() = default;
120};
121
123template <typename T, typename Allocator>
124[[nodiscard]] Buffer<T, Allocator>
125bufferOf(Allocator const & allocator)
126{
127 return Buffer<T, Allocator>(ReBound<Allocator, T>(allocator));
128}
129
133template <typename T>
134struct AllocatorTypeOf
135{};
136
141template <typename T>
142 requires requires { typename T::allocator_type; }
143struct AllocatorTypeOf<T>
144{
145 using allocator_type = typename T::allocator_type;
146};
147
148} // namespace internal
149
150} // namespace Emrys
The macros every header includes first.
std::allocator< std::byte > DefaultAllocator
The allocator a type with a run-time count uses unless given one.
Definition Allocation.h:47
The most elements a container will hold, reserved once: a mixture's components or a particle set's pa...
Definition Allocation.h:54
Eigen::Index count
the most elements, at least zero
Definition Allocation.h:55