1 // Allocators -*- C++ -*-
3 // Copyright (C) 2001-2012 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
26 * Copyright (c) 1996-1997
27 * Silicon Graphics Computer Systems, Inc.
29 * Permission to use, copy, modify, distribute and sell this software
30 * and its documentation for any purpose is hereby granted without fee,
31 * provided that the above copyright notice appear in all copies and
32 * that both that copyright notice and this permission notice appear
33 * in supporting documentation. Silicon Graphics makes no
34 * representations about the suitability of this software for any
35 * purpose. It is provided "as is" without express or implied warranty.
38 /** @file bits/allocator.h
39 * This is an internal header file, included by other library headers.
40 * Do not attempt to use it directly. @headername{memory}
44 #define _ALLOCATOR_H 1
46 // Define the base class to std::allocator.
47 #include <bits/c++allocator.h>
48 #if __cplusplus >= 201103L
49 #include <type_traits>
52 namespace std
_GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
57 * @defgroup allocators Allocators
60 * Classes encapsulating memory operations.
65 template<typename _Tp
>
68 /// allocator<void> specialization.
73 typedef size_t size_type
;
74 typedef ptrdiff_t difference_type
;
75 typedef void* pointer
;
76 typedef const void* const_pointer
;
77 typedef void value_type
;
79 template<typename _Tp1
>
81 { typedef allocator
<_Tp1
> other
; };
83 #if __cplusplus >= 201103L
84 // _GLIBCXX_RESOLVE_LIB_DEFECTS
85 // 2103. std::allocator propagate_on_container_move_assignment
86 typedef true_type propagate_on_container_move_assignment
;
91 * @brief The @a standard allocator, as per [20.4].
93 * See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt04ch11.html
94 * for further details.
96 * @tparam _Tp Type of allocated object.
98 template<typename _Tp
>
99 class allocator
: public __allocator_base
<_Tp
>
102 typedef size_t size_type
;
103 typedef ptrdiff_t difference_type
;
104 typedef _Tp
* pointer
;
105 typedef const _Tp
* const_pointer
;
106 typedef _Tp
& reference
;
107 typedef const _Tp
& const_reference
;
108 typedef _Tp value_type
;
110 template<typename _Tp1
>
112 { typedef allocator
<_Tp1
> other
; };
114 #if __cplusplus >= 201103L
115 // _GLIBCXX_RESOLVE_LIB_DEFECTS
116 // 2103. std::allocator propagate_on_container_move_assignment
117 typedef true_type propagate_on_container_move_assignment
;
120 allocator() throw() { }
122 allocator(const allocator
& __a
) throw()
123 : __allocator_base
<_Tp
>(__a
) { }
125 template<typename _Tp1
>
126 allocator(const allocator
<_Tp1
>&) throw() { }
128 ~allocator() throw() { }
130 // Inherit everything else.
133 template<typename _T1
, typename _T2
>
135 operator==(const allocator
<_T1
>&, const allocator
<_T2
>&)
138 template<typename _Tp
>
140 operator==(const allocator
<_Tp
>&, const allocator
<_Tp
>&)
143 template<typename _T1
, typename _T2
>
145 operator!=(const allocator
<_T1
>&, const allocator
<_T2
>&)
148 template<typename _Tp
>
150 operator!=(const allocator
<_Tp
>&, const allocator
<_Tp
>&)
153 /// Declare uses_allocator so it can be specialized in \<queue\> etc.
154 template<typename
, typename
>
155 struct uses_allocator
;
161 // Inhibit implicit instantiations for required instantiations,
162 // which are defined via explicit instantiations elsewhere.
163 #if _GLIBCXX_EXTERN_TEMPLATE
164 extern template class allocator
<char>;
165 extern template class allocator
<wchar_t>;
169 #undef __allocator_base
171 // To implement Option 3 of DR 431.
172 template<typename _Alloc
, bool = __is_empty(_Alloc
)>
174 { static void _S_do_it(_Alloc
&, _Alloc
&) { } };
176 template<typename _Alloc
>
177 struct __alloc_swap
<_Alloc
, false>
180 _S_do_it(_Alloc
& __one
, _Alloc
& __two
)
182 // Precondition: swappable allocators.
188 // Optimize for stateless allocators.
189 template<typename _Alloc
, bool = __is_empty(_Alloc
)>
193 _S_do_it(const _Alloc
&, const _Alloc
&)
197 template<typename _Alloc
>
198 struct __alloc_neq
<_Alloc
, false>
201 _S_do_it(const _Alloc
& __one
, const _Alloc
& __two
)
202 { return __one
!= __two
; }
205 #if __cplusplus >= 201103L
206 template<typename _Tp
, bool
207 = __or_
<is_copy_constructible
<typename
_Tp::value_type
>,
208 is_nothrow_move_constructible
<typename
_Tp::value_type
>>::value
>
209 struct __shrink_to_fit_aux
210 { static bool _S_do_it(_Tp
&) { return false; } };
212 template<typename _Tp
>
213 struct __shrink_to_fit_aux
<_Tp
, true>
220 _Tp(__make_move_if_noexcept_iterator(__c
.begin()),
221 __make_move_if_noexcept_iterator(__c
.end()),
222 __c
.get_allocator()).swap(__c
);
231 _GLIBCXX_END_NAMESPACE_VERSION