1 // Allocators -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
27 * Copyright (c) 1996-1997
28 * Silicon Graphics Computer Systems, Inc.
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Silicon Graphics makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
39 /** @file bits/allocator.h
40 * This is an internal header file, included by other library headers.
41 * Do not attempt to use it directly. @headername{memory}
45 #define _ALLOCATOR_H 1
47 // Define the base class to std::allocator.
48 #include <bits/c++allocator.h>
50 namespace std _GLIBCXX_VISIBILITY(default)
52 _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 * @defgroup allocators Allocators
58 * Classes encapsulating memory operations.
63 template<typename _Tp>
66 /// allocator<void> specialization.
71 typedef size_t size_type;
72 typedef ptrdiff_t difference_type;
73 typedef void* pointer;
74 typedef const void* const_pointer;
75 typedef void value_type;
77 template<typename _Tp1>
79 { typedef allocator<_Tp1> other; };
83 * @brief The @a standard allocator, as per [20.4].
85 * See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt04ch11.html
86 * for further details.
88 template<typename _Tp>
89 class allocator: public __glibcxx_base_allocator<_Tp>
92 typedef size_t size_type;
93 typedef ptrdiff_t difference_type;
95 typedef const _Tp* const_pointer;
96 typedef _Tp& reference;
97 typedef const _Tp& const_reference;
98 typedef _Tp value_type;
100 template<typename _Tp1>
102 { typedef allocator<_Tp1> other; };
104 allocator() throw() { }
106 allocator(const allocator& __a) throw()
107 : __glibcxx_base_allocator<_Tp>(__a) { }
109 template<typename _Tp1>
110 allocator(const allocator<_Tp1>&) throw() { }
112 ~allocator() throw() { }
114 // Inherit everything else.
117 template<typename _T1, typename _T2>
119 operator==(const allocator<_T1>&, const allocator<_T2>&)
122 template<typename _Tp>
124 operator==(const allocator<_Tp>&, const allocator<_Tp>&)
127 template<typename _T1, typename _T2>
129 operator!=(const allocator<_T1>&, const allocator<_T2>&)
132 template<typename _Tp>
134 operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
141 // Inhibit implicit instantiations for required instantiations,
142 // which are defined via explicit instantiations elsewhere.
143 #if _GLIBCXX_EXTERN_TEMPLATE
144 extern template class allocator<char>;
145 extern template class allocator<wchar_t>;
149 #undef __glibcxx_base_allocator
151 // To implement Option 3 of DR 431.
152 template<typename _Alloc, bool = __is_empty(_Alloc)>
154 { static void _S_do_it(_Alloc&, _Alloc&) { } };
156 template<typename _Alloc>
157 struct __alloc_swap<_Alloc, false>
160 _S_do_it(_Alloc& __one, _Alloc& __two)
162 // Precondition: swappable allocators.
168 // Optimize for stateless allocators.
169 template<typename _Alloc, bool = __is_empty(_Alloc)>
173 _S_do_it(const _Alloc&, const _Alloc&)
177 template<typename _Alloc>
178 struct __alloc_neq<_Alloc, false>
181 _S_do_it(const _Alloc& __one, const _Alloc& __two)
182 { return __one != __two; }
185 #ifdef __GXX_EXPERIMENTAL_CXX0X__
186 template<typename _Tp, bool
187 = __or_<is_copy_constructible<typename _Tp::value_type>,
188 is_nothrow_move_constructible<typename _Tp::value_type>>::value>
189 struct __shrink_to_fit_aux
190 { static bool _S_do_it(_Tp&) { return false; } };
192 template<typename _Tp>
193 struct __shrink_to_fit_aux<_Tp, true>
200 _Tp(__make_move_if_noexcept_iterator(__c.begin()),
201 __make_move_if_noexcept_iterator(__c.end()),
202 __c.get_allocator()).swap(__c);
210 // Declare uses_allocator so it can be specialized in \<queue\> etc.
211 template<typename, typename>
212 struct uses_allocator;
215 _GLIBCXX_END_NAMESPACE_VERSION