1 #ifndef SIPLASPLAS_ALLOCATOR_STL_ALLOCATOR_HPP 2 #define SIPLASPLAS_ALLOCATOR_STL_ALLOCATOR_HPP 6 #include <ctti/type_id.hpp> 11 template<
typename T,
typename Allocator>
16 using const_pointer =
const T*;
18 using const_reference =
const T&;
20 using propagate_on_container_move_assignment = std::true_type;
47 Allocator{ std::move( static_cast<const Allocator&>(alloc) ) }
52 return *
static_cast<const Allocator*
>(
this);
60 pointer allocate(std::size_t count)
62 const std::size_t blockSize =
sizeof(value_type)*count;
63 char* user_ptr =
reinterpret_cast<char*
>(Allocator::allocate(blockSize,
alignof(value_type)));
67 return reinterpret_cast<pointer
>(user_ptr);
71 throw std::bad_alloc{};
75 void deallocate(pointer ptr, std::size_t count)
77 Allocator::deallocate(ptr,
sizeof(value_type)*count);
80 template<
typename... Args>
81 void construct(pointer ptr, Args&&... args)
83 new(ptr) value_type{std::forward<Args>(args)...};
86 void destroy(pointer ptr)
99 return lhs.raw_allocator() == rhs.raw_allocator();
104 return !(lhs == rhs);
107 std::string dump()
const 109 std::ostringstream os;
111 os <<
"STLAllocator adapter for " << ctti::type_id<Allocator>().name() <<
": \n" 112 " - Type: " << ctti::type_id<T>().name() <<
" (" <<
sizeof(T) <<
" bytes, alignment: " <<
alignof(T) <<
")\n" 113 << Allocator::dump();
119 template<
typename T,
typename Allocator>
122 return { std::forward<Allocator>(alloc) };
126 #endif // SIPLASPLAS_ALLOCATOR_STL_ALLOCATOR_HPP Definition: messaging.hpp:8
Definition: stl_allocator.hpp:12
constexpr auto end(const Sequence &sequence)
Returns an iterator pointing to the end of a sequence.
Definition: algorithm.hpp:86
constexpr auto begin(const Sequence &sequence)
Returns an iterator pointing to the beginning of a sequence.
Definition: algorithm.hpp:62
Definition: stl_allocator.hpp:92