1 // Allocators -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 // 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.
40 * This is an internal header file, included by other library headers.
41 * You should not attempt to use it directly.
45 #define _ALLOCATOR_H 1
47 // Define the base class to std::allocator.
48 #include <bits/c++allocator.h>
50 _GLIBCXX_BEGIN_NAMESPACE(std
)
53 * @defgroup allocators Allocators
56 * Classes encapsulating memory operations.
59 template<typename _Tp
>
62 /// allocator<void> specialization.
67 typedef size_t size_type
;
68 typedef ptrdiff_t difference_type
;
69 typedef void* pointer
;
70 typedef const void* const_pointer
;
71 typedef void value_type
;
73 template<typename _Tp1
>
75 { typedef allocator
<_Tp1
> other
; };
79 * @brief The "standard" allocator, as per [20.4].
83 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt04ch11.html
85 template<typename _Tp
>
86 class allocator
: public __glibcxx_base_allocator
<_Tp
>
89 typedef size_t size_type
;
90 typedef ptrdiff_t difference_type
;
92 typedef const _Tp
* const_pointer
;
93 typedef _Tp
& reference
;
94 typedef const _Tp
& const_reference
;
95 typedef _Tp value_type
;
97 template<typename _Tp1
>
99 { typedef allocator
<_Tp1
> other
; };
101 allocator() throw() { }
103 allocator(const allocator
& __a
) throw()
104 : __glibcxx_base_allocator
<_Tp
>(__a
) { }
106 template<typename _Tp1
>
107 allocator(const allocator
<_Tp1
>&) throw() { }
109 ~allocator() throw() { }
111 // Inherit everything else.
114 template<typename _T1
, typename _T2
>
116 operator==(const allocator
<_T1
>&, const allocator
<_T2
>&)
119 template<typename _Tp
>
121 operator==(const allocator
<_Tp
>&, const allocator
<_Tp
>&)
124 template<typename _T1
, typename _T2
>
126 operator!=(const allocator
<_T1
>&, const allocator
<_T2
>&)
129 template<typename _Tp
>
131 operator!=(const allocator
<_Tp
>&, const allocator
<_Tp
>&)
134 // Inhibit implicit instantiations for required instantiations,
135 // which are defined via explicit instantiations elsewhere.
136 // NB: This syntax is a GNU extension.
137 #if _GLIBCXX_EXTERN_TEMPLATE
138 extern template class allocator
<char>;
139 extern template class allocator
<wchar_t>;
143 #undef __glibcxx_base_allocator
145 // To implement Option 3 of DR 431.
146 template<typename _Alloc
, bool = __is_empty(_Alloc
)>
148 { static void _S_do_it(_Alloc
&, _Alloc
&) { } };
150 template<typename _Alloc
>
151 struct __alloc_swap
<_Alloc
, false>
154 _S_do_it(_Alloc
& __one
, _Alloc
& __two
)
156 // Precondition: swappable allocators.
162 // Optimize for stateless allocators.
163 template<typename _Alloc
, bool = __is_empty(_Alloc
)>
167 _S_do_it(const _Alloc
&, const _Alloc
&)
171 template<typename _Alloc
>
172 struct __alloc_neq
<_Alloc
, false>
175 _S_do_it(const _Alloc
& __one
, const _Alloc
& __two
)
176 { return __one
!= __two
; }
179 _GLIBCXX_END_NAMESPACE