1 // Allocators -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
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 2, 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 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 * Copyright (c) 1996-1997
33 * Silicon Graphics Computer Systems, Inc.
35 * Permission to use, copy, modify, distribute and sell this software
36 * and its documentation for any purpose is hereby granted without fee,
37 * provided that the above copyright notice appear in all copies and
38 * that both that copyright notice and this permission notice appear
39 * in supporting documentation. Silicon Graphics makes no
40 * representations about the suitability of this software for any
41 * purpose. It is provided "as is" without express or implied warranty.
45 * This is an internal header file, included by other library headers.
46 * You should not attempt to use it directly.
50 #define _ALLOCATOR_H 1
52 // Define the base class to std::allocator.
53 #include <bits/c++allocator.h>
55 #include <bits/cpp_type_traits.h> // for __is_empty
57 _GLIBCXX_BEGIN_NAMESPACE(std
)
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].
82 * http://gcc.gnu.org/onlinedocs/libstdc++/20_util/allocator.html
84 template<typename _Tp
>
85 class allocator
: public __glibcxx_base_allocator
<_Tp
>
88 typedef size_t size_type
;
89 typedef ptrdiff_t difference_type
;
91 typedef const _Tp
* const_pointer
;
92 typedef _Tp
& reference
;
93 typedef const _Tp
& const_reference
;
94 typedef _Tp value_type
;
96 template<typename _Tp1
>
98 { typedef allocator
<_Tp1
> other
; };
100 allocator() throw() { }
102 allocator(const allocator
& __a
) throw()
103 : __glibcxx_base_allocator
<_Tp
>(__a
) { }
105 template<typename _Tp1
>
106 allocator(const allocator
<_Tp1
>&) throw() { }
108 ~allocator() throw() { }
110 // Inherit everything else.
113 template<typename _T1
, typename _T2
>
115 operator==(const allocator
<_T1
>&, const allocator
<_T2
>&)
118 template<typename _T1
, typename _T2
>
120 operator!=(const allocator
<_T1
>&, const allocator
<_T2
>&)
123 // Inhibit implicit instantiations for required instantiations,
124 // which are defined via explicit instantiations elsewhere.
125 // NB: This syntax is a GNU extension.
126 #if _GLIBCXX_EXTERN_TEMPLATE
127 extern template class allocator
<char>;
128 extern template class allocator
<wchar_t>;
132 #undef __glibcxx_base_allocator
134 // To implement Option 3 of DR 431.
135 template<typename _Alloc
, bool = std::__is_empty
<_Alloc
>::__value
>
137 { static void _S_do_it(_Alloc
&, _Alloc
&) { } };
139 template<typename _Alloc
>
140 struct __alloc_swap
<_Alloc
, false>
143 _S_do_it(_Alloc
& __one
, _Alloc
& __two
)
145 // Precondition: swappable allocators.
151 _GLIBCXX_END_NAMESPACE