1 // Allocators -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
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 _GLIBCXX_BEGIN_NAMESPACE(std)
57 template<typename _Tp>
60 /// allocator<void> specialization.
65 typedef size_t size_type;
66 typedef ptrdiff_t difference_type;
67 typedef void* pointer;
68 typedef const void* const_pointer;
69 typedef void value_type;
71 template<typename _Tp1>
73 { typedef allocator<_Tp1> other; };
77 * @brief The "standard" allocator, as per [20.4].
80 * http://gcc.gnu.org/onlinedocs/libstdc++/20_util/allocator.html
82 template<typename _Tp>
83 class allocator: public __glibcxx_base_allocator<_Tp>
86 typedef size_t size_type;
87 typedef ptrdiff_t difference_type;
89 typedef const _Tp* const_pointer;
90 typedef _Tp& reference;
91 typedef const _Tp& const_reference;
92 typedef _Tp value_type;
94 template<typename _Tp1>
96 { typedef allocator<_Tp1> other; };
98 allocator() throw() { }
100 allocator(const allocator& __a) throw()
101 : __glibcxx_base_allocator<_Tp>(__a) { }
103 template<typename _Tp1>
104 allocator(const allocator<_Tp1>&) throw() { }
106 ~allocator() throw() { }
108 // Inherit everything else.
111 template<typename _T1, typename _T2>
113 operator==(const allocator<_T1>&, const allocator<_T2>&)
116 template<typename _T1, typename _T2>
118 operator!=(const allocator<_T1>&, const allocator<_T2>&)
121 // Inhibit implicit instantiations for required instantiations,
122 // which are defined via explicit instantiations elsewhere.
123 // NB: This syntax is a GNU extension.
124 #if _GLIBCXX_EXTERN_TEMPLATE
125 extern template class allocator<char>;
126 extern template class allocator<wchar_t>;
130 #undef __glibcxx_base_allocator
132 // To implement Option 3 of DR 431.
133 template<typename _Alloc, bool = __is_empty(_Alloc)>
135 { static void _S_do_it(_Alloc&, _Alloc&) { } };
137 template<typename _Alloc>
138 struct __alloc_swap<_Alloc, false>
141 _S_do_it(_Alloc& __one, _Alloc& __two)
143 // Precondition: swappable allocators.
149 _GLIBCXX_END_NAMESPACE