29 #ifndef _MALLOC_ALLOCATOR_H
30 #define _MALLOC_ALLOCATOR_H 1
36 #if __cplusplus >= 201103L
40 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 template<
typename _Tp>
56 class malloc_allocator
59 typedef size_t size_type;
60 typedef ptrdiff_t difference_type;
62 typedef const _Tp* const_pointer;
63 typedef _Tp& reference;
64 typedef const _Tp& const_reference;
65 typedef _Tp value_type;
67 template<
typename _Tp1>
69 {
typedef malloc_allocator<_Tp1> other; };
71 #if __cplusplus >= 201103L
77 malloc_allocator() _GLIBCXX_USE_NOEXCEPT { }
79 malloc_allocator(
const malloc_allocator&) _GLIBCXX_USE_NOEXCEPT { }
81 template<
typename _Tp1>
82 malloc_allocator(
const malloc_allocator<_Tp1>&)
83 _GLIBCXX_USE_NOEXCEPT { }
85 ~malloc_allocator() _GLIBCXX_USE_NOEXCEPT { }
88 address(reference __x)
const _GLIBCXX_NOEXCEPT
92 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
98 allocate(size_type __n,
const void* = 0)
100 if (__n > this->max_size())
101 std::__throw_bad_alloc();
103 pointer __ret =
static_cast<_Tp*
>(std::malloc(__n *
sizeof(_Tp)));
105 std::__throw_bad_alloc();
111 deallocate(pointer __p, size_type)
112 { std::free(static_cast<void*>(__p)); }
115 max_size() const _GLIBCXX_USE_NOEXCEPT
116 {
return size_t(-1) /
sizeof(_Tp); }
118 #if __cplusplus >= 201103L
119 template<
typename _Up,
typename... _Args>
121 construct(_Up* __p, _Args&&... __args)
122 { ::new((
void *)__p) _Up(std::
forward<_Args>(__args)...); }
124 template<typename _Up>
126 destroy(_Up* __p) { __p->~_Up(); }
131 construct(pointer __p,
const _Tp& __val)
132 { ::new((
void *)__p) value_type(__val); }
135 destroy(pointer __p) { __p->~_Tp(); }
139 template<
typename _Tp>
141 operator==(
const malloc_allocator<_Tp>&,
const malloc_allocator<_Tp>&)
144 template<
typename _Tp>
146 operator!=(
const malloc_allocator<_Tp>&,
const malloc_allocator<_Tp>&)
149 _GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.