#pragma once #include "PoolAllocator.hpp" #include #ifdef _WIN32 # include #endif namespace sprawl { namespace memory { template > class StlWrapper { public: typedef StlWrapper other; typedef T value_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef T const& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; #ifdef _WIN32 # if _HAS_CPP0X typedef std::false_type propagate_on_container_copy_assignment; typedef std::false_type propagate_on_container_move_assignment; typedef std::false_type propagate_on_container_swap; StlWrapper select_on_container_copy_construction() const { // return this allocator return (*this); } # endif #endif template struct rebind { typedef StlWrapper::otherAllocator> other; }; value_type* address(value_type& val) const { return reinterpret_cast(&reinterpret_cast(val)); } StlWrapper() { // } StlWrapper(StlWrapper const& /*other*/) { // } template StlWrapper(const StlWrapper& /*other*/) { // } template StlWrapper& operator=(StlWrapper const& /*other*/) { return (*this); } bool operator==(const StlWrapper& /*other*/) const { return true; } bool operator!=(const StlWrapper& /*other*/) const { return false; } template bool operator==(const StlWrapper& /*other*/) const { return false; } template bool operator!=(const StlWrapper& /*other*/) const { return true; } void deallocate(value_type* ptr, size_type /*unused*/) { allocator::free(ptr); } value_type* allocate(size_type count) { if(count == 1) { return (value_type*)(allocator::alloc()); } return (value_type*)(allocator::alloc(count)); } value_type* allocate(size_type count, const void* /*unused*/) { return (value_type*)(allocate(count)); } void construct(value_type* ptr) { ::new ((void *)ptr) T(); } void construct(value_type* ptr, value_type const& other) { ::new ((void *)ptr) T(other); } #if (defined(_WIN32) && _MSC_VER < 1800) # define SPRAWL_ALLOC_MEMBER_CONSTRUCT( \ TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, CALL_OPT, X2, X3, X4) \ template \ void construct(_Objty *_Ptr COMMA LIST(_TYPE_REFREF_ARG)) \ { \ ::new ((void *)_Ptr) _Objty(LIST(_FORWARD_ARG)); \ } _VARIADIC_EXPAND_0X(SPRAWL_ALLOC_MEMBER_CONSTRUCT, , , , ) # undef SPRAWL_ALLOC_MEMBER_CONSTRUCT #else template< typename T2, typename... Args > void construct( T2* ptr, Args&&... args ) { ::new ((void*)ptr) T2(std::forward(args)...); } #endif template void destroy(T2* ptr) { (void)(ptr); ptr->~T2(); } size_t max_size() const { return ((size_t)(-1) / sizeof (T)); } }; } }