18 #ifndef ION_BASE_STLALLOC_STLALLOCATOR_H_
19 #define ION_BASE_STLALLOC_STLALLOCATOR_H_
22 #include <type_traits>
35 template <
typename T>
class StlAllocator :
public std::allocator<T> {
39 typedef typename std::allocator<T>::size_type
SizeType;
48 : allocator_(allocator) {}
52 : allocator_(a.allocator_) {}
59 return reinterpret_cast<Pointer>(p);
80 const VoidOrT* select_overload = NULL;
81 construct_impl(select_overload, p, val);
83 template <
typename... Args>
91 const VoidOrT* select_overload = NULL;
92 construct_impl(select_overload, p, std::forward<Args>(args)...);
94 template <
class U,
class... Args>
103 const VoidOrU* select_overload = NULL;
104 construct_impl(select_overload, p, std::forward<Args>(args)...);
107 template <
typename U>
116 void construct_impl(
const void* dummy,
Pointer p,
const T& val) {
117 std::allocator<T>::construct(p, val);
119 template <
typename... Args>
120 void construct_impl(
const void* dummy,
Pointer p,
122 std::allocator<T>::construct(p, std::forward<Args>(args)...);
124 template <
class U,
class... Args>
125 void construct_impl(
const void* dummy, U* p, Args&&... args) {
126 std::allocator<T>::construct(p, std::forward<Args>(args)...);
131 void construct_impl(
const T* dummy,
Pointer p,
const T& val) {
132 Allocatable::SetPlacementAllocator(allocator_.
Get());
133 std::allocator<T>::construct(p, val);
134 Allocatable::SetPlacementAllocator(NULL);
136 template <
typename... Args>
137 void construct_impl(
const T* dummy,
Pointer p, Args&&... args) {
138 Allocatable::SetPlacementAllocator(allocator_.
Get());
139 std::allocator<T>::construct(p, std::forward<Args>(args)...);
140 Allocatable::SetPlacementAllocator(NULL);
142 template <
class U,
class... Args>
143 void construct_impl(
const U* dummy, U* p, Args&&... args) {
144 Allocatable::SetPlacementAllocator(allocator_.
Get());
145 std::allocator<T>::construct(p, std::forward<Args>(args)...);
146 Allocatable::SetPlacementAllocator(NULL);
156 template <
typename T,
int N>
163 :
StlAllocator<
T>(allocator), current_(NULL), inlined_(true) {}
169 inlined_(a.inlined_) {}
172 template <
typename U>
176 inlined_(a.inlined_) {}
180 if (n <= N && inlined_) {
181 if (current_ == reinterpret_cast<T*>(&storage_[0]))
182 current_ =
reinterpret_cast<T*
>(&storage_[
sizeof(
T) * N]);
184 current_ =
reinterpret_cast<T*
>(&storage_[0]);
185 return reinterpret_cast<Pointer>(current_);
194 if (p != reinterpret_cast<Pointer>(&storage_) &&
195 p != reinterpret_cast<Pointer>(&storage_[
sizeof(
T) * N])) {
204 template <
typename U,
typename V>
210 template <
typename U>
227 ION_ALIGN(16) char storage_[sizeof(
T) * N * 2];
236 template <class T1, class T2>
241 template <
class T1,
class T2>
257 template <
class T1,
class T2,
int N1,
int N2>
263 template <
class T1,
class T2,
int N1,
int N2>
272 #endif // ION_BASE_STLALLOC_STLALLOCATOR_H_
StlAllocator< T >::ConstPointer ConstPointer
StlAllocator is derived std::allocator class that allows an Ion Allocator to be used for STL containe...
std::allocator< T >::size_type SizeType
StlAllocator< V >::template rebind< U >::other other
void construct(Pointer p, const T &val)
Replace the construct() functions so that we can pass an Allocator to Allocatable types...
std::allocator< T >::pointer Pointer
void construct(U *p, Args &&...args)
StlInlinedAllocator< U, N > other
const AllocatorPtr & GetAllocator() const
Returns the Allocator used by this.
StlInlinedAllocator(const StlInlinedAllocator< T, N > &a)
Copy constructor.
void deallocate(Pointer p, SizeType n)
SharedPtr< Allocator > AllocatorPtr
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
StlAllocator< T >::Pointer Pointer
StlInlinedAllocator is a derived StlAllocator class that uses inlined storage for its first N element...
Pointer allocate(SizeType n, ConstPointer hint=0)
Pointer allocate(SizeType n, ConstPointer hint=0)
StlInlinedAllocator(const StlInlinedAllocator< U, N > &a)
This copy constructor cannot be explicit because older versions of STL seem to implicitly cast betwee...
Windows uses transient proxy allocators.
std::allocator< T >::const_pointer ConstPointer
StlAllocator< T >::SizeType SizeType
void DeallocateMemory(void *p)
Deallocates a previously-allocated memory block.
RebindHelper< U, T >::other other
void * AllocateMemory(size_t size)
Allocates memory of the given size.
std::true_type propagate_on_container_move_assignment
These allocator traits affect the behavior of containers such as AllocVector.
bool operator==(const StlAllocator< T1 > &lhs, const StlAllocator< T2 > &rhs)
Each StlAllocator holds an Allocator.
StlAllocator(const StlAllocator< U > &a)
This copy constructor cannot be explicit because older versions of STL seem to implicitly cast betwee...
StlAllocator(const AllocatorPtr &allocator)
bool operator!=(const StlAllocator< T1 > &lhs, const StlAllocator< T2 > &rhs)
void deallocate(Pointer p, SizeType n)
void construct(Pointer p, Args &&...args)
StlInlinedAllocator(const AllocatorPtr &allocator)
std::true_type propagate_on_container_swap