Zserio C++17 runtime library 1.3.0
Built for Zserio 2.20.0
Loading...
Searching...
No Matches
AllocatorHolder.h
Go to the documentation of this file.
1#ifndef ZSERIO_ALLOCATOR_HOLDER_H_INC
2#define ZSERIO_ALLOCATOR_HOLDER_H_INC
3
4#include <type_traits>
5#include <utility>
6
7namespace zserio
8{
9
13template <typename ALLOC, bool EMPTY = std::is_empty<ALLOC>::value>
15{
16public:
17 using allocator_type = ALLOC;
18
23 m_allocator()
24 {}
25
31 explicit AllocatorHolder(const allocator_type& allocator) :
32 m_allocator(allocator)
33 {}
34
40 explicit AllocatorHolder(allocator_type&& allocator) :
41 m_allocator(std::move(allocator))
42 {}
43
48 ~AllocatorHolder() = default;
49
50 AllocatorHolder(const AllocatorHolder& other) = default;
51 AllocatorHolder& operator=(const AllocatorHolder& other) = default;
52
53 AllocatorHolder(AllocatorHolder&& other) = default;
65 {
66 return get_allocator_ref();
67 }
68
69protected:
75 void set_allocator(const allocator_type& allocator)
76 {
77 m_allocator = allocator;
78 }
79
85 void set_allocator(allocator_type&& allocator)
86 {
87 m_allocator = std::move(allocator);
88 }
89
96 {
97 return m_allocator;
98 }
99
106 {
107 return m_allocator;
108 }
109
110private:
111 allocator_type m_allocator;
112};
113
118template <typename ALLOC>
119class AllocatorHolder<ALLOC, true>
120{
121public:
122 using allocator_type = ALLOC;
123
130 {}
131
136 AllocatorHolder() = default;
137 ~AllocatorHolder() = default;
138
139 AllocatorHolder(const AllocatorHolder& other) = default;
140 AllocatorHolder& operator=(const AllocatorHolder& other) = default;
141
154 {
155 return {};
156 }
157
158protected:
165 {}
166
174
181 {
182 return {};
183 }
184};
185
186} // namespace zserio
187
188#endif // ifndef ZSERIO_ALLOCATOR_HOLDER_H_INC
AllocatorHolder & operator=(const AllocatorHolder &other)=default
AllocatorHolder & operator=(AllocatorHolder &&other)=default
AllocatorHolder(AllocatorHolder &&other)=default
AllocatorHolder(const AllocatorHolder &other)=default
void set_allocator(const allocator_type &)
allocator_type get_allocator() const
AllocatorHolder(AllocatorHolder &&other)=default
const allocator_type & get_allocator_ref() const
AllocatorHolder(allocator_type &&allocator)
AllocatorHolder & operator=(const AllocatorHolder &other)=default
void set_allocator(const allocator_type &allocator)
AllocatorHolder & operator=(AllocatorHolder &&other)=default
void set_allocator(allocator_type &&allocator)
AllocatorHolder(const allocator_type &allocator)
AllocatorHolder(const AllocatorHolder &other)=default
allocator_type & get_allocator_ref()