1 #ifndef ZSERIO_ALLOCATOR_PROPAGATING_COPY_H_INC 2 #define ZSERIO_ALLOCATOR_PROPAGATING_COPY_H_INC 30 template <
typename T,
typename ALLOC>
33 template <
typename T,
typename ALLOC,
typename ALLOC2>
37 template <
typename T,
typename ALLOC>
40 template <
typename T,
typename ALLOC,
typename ALLOC2>
49 template <
typename CharT,
typename Traits,
typename ALLOC1,
typename ALLOC2>
50 std::basic_string<CharT, Traits, ALLOC1> allocatorPropagatingCopyDefault(std::true_type,
51 const std::basic_string<CharT, Traits, ALLOC1>& source,
const ALLOC2& allocator)
53 return std::basic_string<CharT, Traits, ALLOC1>(source.c_str(), source.length(), allocator);
58 template <
typename ALLOC,
typename ALLOC2>
59 std::vector<bool, ALLOC> allocatorPropagatingCopyVec(
60 std::false_type,
const std::vector<bool, ALLOC>& source,
const ALLOC2& allocator)
62 std::vector<bool, ALLOC> ret(allocator);
63 ret.reserve(source.size());
64 ret.assign(source.begin(), source.end());
69 template <
typename T,
typename ALLOC>
70 T allocatorPropagatingCopyDefault(std::true_type,
const T& source,
const ALLOC& allocator)
72 return T(source, allocator);
76 template <
typename T,
typename ALLOC>
77 T allocatorPropagatingCopyDefault(std::false_type,
const T& source,
const ALLOC&)
83 template <
typename T,
typename ALLOC>
84 T allocatorPropagatingCopyPropagating(std::true_type,
const T& source,
const ALLOC& allocator)
86 return T(PropagateAllocator, source, allocator);
90 template <
typename T,
typename ALLOC>
91 T allocatorPropagatingCopyPropagating(std::true_type,
NoInitT,
const T& source,
const ALLOC& allocator)
93 return T(PropagateAllocator,
NoInit, source, allocator);
97 template <
typename T,
typename ALLOC>
98 T allocatorPropagatingCopyPropagating(std::false_type,
const T& source,
const ALLOC& allocator)
100 return allocatorPropagatingCopyDefault(std::uses_allocator<T, ALLOC>(), source, allocator);
104 template <
typename T,
typename ALLOC,
typename ALLOC2>
105 std::vector<T, ALLOC> allocatorPropagatingCopyVec(
106 std::true_type,
const std::vector<T, ALLOC>& source,
const ALLOC2& allocator)
108 std::vector<T, ALLOC> result(allocator);
109 result.reserve(source.size());
110 std::transform(source.begin(), source.end(), std::back_inserter(result),
116 template <
typename T,
typename ALLOC,
typename ALLOC2>
117 std::vector<T, ALLOC> allocatorPropagatingCopyVec(
118 std::true_type,
NoInitT,
const std::vector<T, ALLOC>& source,
const ALLOC2& allocator)
120 std::vector<T, ALLOC> result(allocator);
121 result.reserve(source.size());
122 std::transform(source.begin(), source.end(), std::back_inserter(result),
128 template <
typename T,
typename ALLOC,
typename ALLOC2>
129 std::vector<T, ALLOC> allocatorPropagatingCopyVec(
130 std::false_type,
const std::vector<T, ALLOC>& source,
const ALLOC2& allocator)
132 return std::vector<T, ALLOC>(source, allocator);
135 template <
typename T,
typename ALLOC>
136 T allocatorPropagatingCopyImpl(
const T& source,
const ALLOC& allocator)
138 return allocatorPropagatingCopyPropagating(
139 std::is_constructible<T, PropagateAllocatorT, T, ALLOC>(), source, allocator);
142 template <
typename T,
typename ALLOC>
143 T allocatorPropagatingCopyImpl(
NoInitT,
const T& source,
const ALLOC& allocator)
145 static_assert(std::is_constructible<T, NoInitT, T>::value,
"Can be used only for parameterized compounds!");
147 return allocatorPropagatingCopyPropagating(
148 std::is_constructible<T, PropagateAllocatorT, NoInitT, T, ALLOC>(),
NoInit, source, allocator);
151 template <
typename T,
typename ALLOC,
typename ALLOC2>
155 if (source.hasValue())
161 template <
typename T,
typename ALLOC,
typename ALLOC2>
165 static_assert(std::is_constructible<T, NoInitT, T>::value,
"Can be used only for parameterized compounds!");
167 if (source.hasValue())
176 template <
typename T,
typename ALLOC>
180 if (source.hasValue())
186 template <
typename T,
typename ALLOC>
190 static_assert(std::is_constructible<T, NoInitT, T>::value,
"Can be used only for parameterized compounds!");
192 if (source.hasValue())
198 template <
typename T,
typename ALLOC,
typename ALLOC2>
213 template <
typename T,
typename ALLOC,
typename ALLOC2>
228 template <
typename T,
typename ALLOC,
typename ALLOC2>
229 std::vector<T, ALLOC> allocatorPropagatingCopyImpl(
230 const std::vector<T, ALLOC>& source,
const ALLOC2& allocator)
232 return allocatorPropagatingCopyVec(std::uses_allocator<T, ALLOC>(), source, allocator);
235 template <
typename T,
typename ALLOC,
typename ALLOC2>
236 std::vector<T, ALLOC> allocatorPropagatingCopyImpl(
237 NoInitT,
const std::vector<T, ALLOC>& source,
const ALLOC2& allocator)
239 static_assert(std::is_constructible<T, NoInitT, T>::value,
"Can be used only for parameterized compounds!");
241 return allocatorPropagatingCopyVec(std::uses_allocator<T, ALLOC>(),
NoInit, source, allocator);
254 template <
typename T,
typename ALLOC>
257 static_assert(!std::is_same<
AnyHolder<ALLOC>, T>::value,
"Cannot be used for AnyHolder!");
259 return detail::allocatorPropagatingCopyImpl(source, allocator);
270 template <
typename T,
typename ALLOC>
273 static_assert(!std::is_same<
AnyHolder<ALLOC>, T>::value,
"Cannot be used for AnyHolder!");
275 return detail::allocatorPropagatingCopyImpl(
NoInit, source, allocator);
286 template <
typename T,
typename ALLOC,
typename ALLOC2>
290 return detail::allocatorPropagatingCopyImpl<T>(source, allocator);
301 template <
typename T,
typename ALLOC,
typename ALLOC2>
305 static_assert(std::is_constructible<T, NoInitT, T>::value,
"Can be used only for parameterized compounds!");
307 return detail::allocatorPropagatingCopyImpl<T>(
NoInit, source, allocator);
312 #endif // ZSERIO_ALLOCATOR_PROPAGATING_COPY_H_INC
detail::heap_optional_holder< T, ALLOC > HeapOptionalHolder
constexpr PropagateAllocatorT PropagateAllocator
T allocatorPropagatingCopy(const T &source, const ALLOC &allocator)
constexpr PropagateAllocatorT()=default
detail::inplace_optional_holder< T > InplaceOptionalHolder