16#ifndef COOK_MEM_ALLOCATOR_H
17#define COOK_MEM_ALLOCATOR_H
37template<
class Context>
72 return m_context.get ();
85 return &m_context.get () == &other.m_context.get ();
98 return !(*
this == other);
102 std::reference_wrapper<Context> m_context;
111template<
class Context,
class Tag>
132 : m_context (getContextForAllocator ())
143 return activeContext ();
152 return getPersistentThreadContext ();
164 return m_context.get ();
177 return &m_context.get () == &other.m_context.get ();
190 return !(*
this == other);
194 template<
class,
class>
200 Context* context = activeContextStorage ();
201 return context !=
nullptr ? *context : getPersistentThreadContext ();
205 activeContextStorage ()
207 static thread_local Context* context =
nullptr;
212 getContextForAllocator ()
214 return activeContext ();
218 getPersistentThreadContext ()
220 static thread_local Context context;
224 std::reference_wrapper<Context> m_context;
234template<
class Context,
class Tag>
261 : m_context (
TLSContextProvider<Context, Tag>::getPersistentThreadContext (), shareArena),
288 Context* m_previousContext;
301 class ContextProvider = MemContextProvider<CachedMemContext<> > >
341 template<
class Prov
ider = ContextProv
ider>
343 typename std::enable_if<
344 std::is_default_constructible<Provider>::value,
345 int>::type* =
nullptr)
380 : m_provider (other.m_provider)
393 : m_provider (other.m_provider)
410 if (size > (std::numeric_limits<size_type>::max) () /
sizeof (
T))
412 throw std::bad_alloc ();
425 throw std::bad_alloc ();
440 m_provider.
get ().deallocate (
ptr);
451 return (std::numeric_limits<size_type>::max) () /
sizeof (
T);
462 template<
class U,
class...
Args>
466 ::new (
static_cast<void*
> (
ptr))
U (std::forward<Args> (
args)...);
490 return m_provider.
get ();
505 return m_provider == other.m_provider;
519 return !(*
this == other);
523 template<
class,
class>
532 return m_provider.
get ().allocate (
bytes);
539 allocateBytes (
size_type bytes, std::true_type)
541 return m_provider.
get ().allocateAligned (bytes,
alignof (T));
544 ContextProvider m_provider;
Definition allocator.h:303
ContextProvider::propagate_on_container_copy_assignment propagate_on_container_copy_assignment
Definition allocator.h:315
Allocator(const Allocator< U, ContextProvider > &other)
Definition allocator.h:392
Allocator(const ContextProvider &provider)
Definition allocator.h:368
void deallocate(pointer ptr, size_type)
Definition allocator.h:438
pointer allocate(size_type size, const void *=nullptr)
Definition allocator.h:408
T & reference
Reference to an allocated object.
Definition allocator.h:310
T value_type
The type of the allocated objects.
Definition allocator.h:307
ContextProvider context_provider_type
The type of the context provider.
Definition allocator.h:305
T * pointer
Pointer to an allocated object.
Definition allocator.h:308
void destroy(U *ptr)
Definition allocator.h:477
std::size_t size_type
The type of object counts.
Definition allocator.h:312
Allocator(const Allocator &other)
Definition allocator.h:379
size_type max_size() const
Definition allocator.h:449
bool operator!=(const Allocator< U, ContextProvider > &other) const
Definition allocator.h:517
ContextProvider::is_always_equal is_always_equal
Definition allocator.h:321
bool operator==(const Allocator< U, ContextProvider > &other) const
Definition allocator.h:503
void construct(U *ptr, Args &&... args)
Definition allocator.h:464
Allocator(context_type &context)
Definition allocator.h:357
std::ptrdiff_t difference_type
The type of pointer differences.
Definition allocator.h:313
const T * const_pointer
Const pointer to an allocated object.
Definition allocator.h:309
ContextProvider::propagate_on_container_move_assignment propagate_on_container_move_assignment
Definition allocator.h:317
const T & const_reference
Const reference to an allocated object.
Definition allocator.h:311
context_type & getContext() const
Definition allocator.h:488
ContextProvider::propagate_on_container_swap propagate_on_container_swap
Definition allocator.h:319
Allocator(typename std::enable_if< std::is_default_constructible< Provider >::value, int >::type *=nullptr)
Definition allocator.h:342
ContextProvider::context_type context_type
The type of the memory context.
Definition allocator.h:306
Definition allocator.h:39
MemContextProvider(Context &context)
Definition allocator.h:59
bool operator==(const MemContextProvider &other) const
Definition allocator.h:83
std::false_type propagate_on_container_move_assignment
Definition allocator.h:46
Context context_type
Definition allocator.h:42
std::false_type is_always_equal
Definition allocator.h:50
Context & get() const
Definition allocator.h:70
bool operator!=(const MemContextProvider &other) const
Definition allocator.h:96
std::false_type propagate_on_container_copy_assignment
Definition allocator.h:44
std::false_type propagate_on_container_swap
Definition allocator.h:48
Definition allocator.h:113
Context & get() const
Definition allocator.h:162
std::true_type propagate_on_container_move_assignment
Definition allocator.h:120
std::true_type propagate_on_container_swap
Definition allocator.h:122
Context context_type
Definition allocator.h:116
std::true_type propagate_on_container_copy_assignment
Definition allocator.h:118
TLSContextProvider()
Definition allocator.h:131
static Context & getThreadContext()
Definition allocator.h:150
bool operator!=(const TLSContextProvider &other) const
Definition allocator.h:188
bool operator==(const TLSContextProvider &other) const
Definition allocator.h:175
std::false_type is_always_equal
Definition allocator.h:124
static Context & getActiveContext()
Definition allocator.h:141
Definition allocator.h:236
TLSContextScope()
Definition allocator.h:242
Context & getContext()
Definition allocator.h:281
TLSContextScope(bool shareArena)
Definition allocator.h:260
Definition allocator.h:29
const std::size_t ALLOCATION_ALIGNMENT
Definition config.h:36
Definition allocator.h:332
Allocator< U, ContextProvider > other
Definition allocator.h:334