cosmopolitan/ctl/allocator_traits.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
1.8 KiB
C
Raw Normal View History

2024-06-29 02:07:35 +00:00
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_ALLOCATOR_TRAITS_H_
#define CTL_ALLOCATOR_TRAITS_H_
2024-06-29 02:07:35 +00:00
#include "integral_constant.h"
namespace ctl {
template<typename Alloc>
struct allocator_traits
{
using allocator_type = Alloc;
using value_type = typename Alloc::value_type;
2024-07-01 14:10:35 +00:00
using pointer = typename Alloc::value_type*;
using const_pointer = const typename Alloc::value_type*;
using void_pointer = void*;
using const_void_pointer = const void*;
2024-07-01 14:10:35 +00:00
using difference_type = ptrdiff_t;
using size_type = size_t;
2024-07-01 10:48:28 +00:00
using propagate_on_container_copy_assignment = ctl::false_type;
using propagate_on_container_move_assignment = ctl::true_type;
using propagate_on_container_swap = ctl::false_type;
using is_always_equal = ctl::true_type;
template<typename T>
2024-07-01 14:10:35 +00:00
struct rebind_alloc
{
using other = typename Alloc::template rebind<T>::other;
};
template<typename T>
2024-07-01 14:10:35 +00:00
using rebind_traits = allocator_traits<typename rebind_alloc<T>::other>;
2024-07-01 10:48:28 +00:00
static pointer allocate(Alloc& a, size_type n)
{
return a.allocate(n);
}
2024-07-01 10:48:28 +00:00
static void deallocate(Alloc& a, pointer p, size_type n)
{
a.deallocate(p, n);
}
template<typename T, typename... Args>
2024-07-01 10:48:28 +00:00
static void construct(Alloc& a, T* p, Args&&... args)
{
::new ((void*)p) T(static_cast<Args&&>(args)...);
}
template<typename T>
2024-07-01 10:48:28 +00:00
static void destroy(Alloc& a, T* p)
{
p->~T();
}
2024-07-01 10:48:28 +00:00
static size_type max_size(const Alloc& a) noexcept
{
2024-07-01 14:10:35 +00:00
return a.max_size();
}
2024-07-01 10:48:28 +00:00
static Alloc select_on_container_copy_construction(const Alloc& a)
{
return a;
}
};
} // namespace ctl
#endif // CTL_ALLOCATOR_TRAITS_H_