47#ifndef LIB_ALLOCATOR_HANDLE_H
48#define LIB_ALLOCATOR_HANDLE_H
91 using AlloT = std::allocator_traits<Allo>;
100 using XAllo = AlloT::template rebind_alloc<X>;
101 if constexpr (std::is_constructible_v<XAllo, Allo>)
107 template<
class ALOT,
typename...ARGS>
111 auto loc = ALOT::allocate (allo, 1);
112 try { ALOT::construct (allo, loc, std::forward<ARGS>(args)...); }
115 ALOT::deallocate (allo, loc, 1);
123 destroy (ALOT::allocator_type& allo, ALOT::pointer elm)
125 ALOT::destroy (allo, elm);
126 ALOT::deallocate (allo, elm, 1);
154 return not (*
this == o);
160 template<
class TY,
typename...ARGS>
164 if constexpr (std::is_same_v<TY, BaseType>)
166 return construct<AlloT> (
baseAllocator(), std::forward<ARGS>(args)...);
170 using XAlloT = AlloT::template rebind_traits<TY>;
171 auto xAllo = adaptAllocator<TY>();
172 return construct<XAlloT> (xAllo, std::forward<ARGS>(args)...);
181 if constexpr (std::is_same_v<TY, BaseType>)
187 using XAlloT = AlloT::template rebind_traits<TY>;
188 auto xAllo = adaptAllocator<TY>();
189 destroy<XAlloT> (xAllo, elm);
200 : std::__and_< std::is_empty<FAC>
201 , std::is_default_constructible<FAC>
226 template<
typename TY>
231 factory.dispose (elm);
234 template<
typename TY>
259 template<
class TY,
typename...ARGS>
263 if constexpr (is_Stateless_v<FAC>)
265 using Handle = std::unique_ptr<TY, void(TY*)>;
266 return Handle{FAC::template create<TY> (std::forward<ARGS> (args)...)
272 using Handle = std::unique_ptr<TY, StatefulDeleter<TY>>;
273 return Handle{FAC::template create<TY> (std::forward<ARGS> (args)...)
295 template<
typename TY>
303 template<
typename...ARGS>
307 return *
new(&
buf_) TY {std::forward<ARGS> (args)...};
313 return * std::launder (
reinterpret_cast<TY*
> (&
buf_));
325 template<
typename...ARGS>
331 return pos->create (std::forward<ARGS> (args)...);
338 ERROR (memory,
"Allocation failed with unknown exception. "
339 "Lumiera errorID=%s", errID?errID:
"??");
Placeholder implementation for a custom allocator.
TY & operator()(ARGS &&...args)
std::list< Allocation > storage_
Generic opaque reference counting handle, for accessing a service and managing its lifecycle.
Adapter to use a generic factory FAC for creating managed object instances with unique ownership.
static void dispose(TY *elm)
auto make_unique(ARGS &&...args)
Factory function: generate object with scoped ownership and automated clean-up.
OwnUniqueAdapter(FAC const &factory)
< Concepts and Adaptors for custom memory management
bool constexpr operator!=(StdFactory< XALO > const &o) const
std::allocator_traits< Allo > AlloT
ALOT::pointer construct(ALOT::allocator_type &allo, ARGS &&...args)
TY * create(ARGS &&...args)
create new element using the embedded allocator
void destroy(ALOT::allocator_type &allo, ALOT::pointer elm)
Allo::value_type BaseType
StdFactory(Allo allo=Allo{})
Create an instance of the adapter factory, forwarding to the embedded standard conforming allocator f...
bool constexpr operator==(StdFactory< XALO > const &o) const
void dispose(TY *elm)
destroy the given element and discard the associated memory
lumiera_err lumiera_error(void)
Get and clear current error state.
Lumiera error handling (C++ interface).
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error.
Implementation namespace for support and library code.
std::byte buf_[sizeof(TY)]
TY & create(ARGS &&...args)
StatefulDeleter(FAC const &anchor)
Metafunction: probe if the given base factory is possibly monostate.