Install gcc-4.4.0-tdm-1-g++-2.tar.gz
[git/jnareb-git.git] / mingw / lib / gcc / mingw32 / 4.4.0 / include / c++ / bits / allocator.h
blob334fee5d17bf31bce4c8f6bd2579207f5b08476e
1 // Allocators -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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 allocator.h
40 * This is an internal header file, included by other library headers.
41 * You should not attempt to use it directly.
44 #ifndef _ALLOCATOR_H
45 #define _ALLOCATOR_H 1
47 // Define the base class to std::allocator.
48 #include <bits/c++allocator.h>
50 _GLIBCXX_BEGIN_NAMESPACE(std)
52 /**
53 * @defgroup allocators Allocators
54 * @ingroup memory
56 * Classes encapsulating memory operations.
59 template<typename _Tp>
60 class allocator;
62 /// allocator<void> specialization.
63 template<>
64 class allocator<void>
66 public:
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>
74 struct rebind
75 { typedef allocator<_Tp1> other; };
78 /**
79 * @brief The "standard" allocator, as per [20.4].
80 * @ingroup allocators
82 * Further details:
83 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt04ch11.html
85 template<typename _Tp>
86 class allocator: public __glibcxx_base_allocator<_Tp>
88 public:
89 typedef size_t size_type;
90 typedef ptrdiff_t difference_type;
91 typedef _Tp* pointer;
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>
98 struct rebind
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>
115 inline bool
116 operator==(const allocator<_T1>&, const allocator<_T2>&)
117 { return true; }
119 template<typename _Tp>
120 inline bool
121 operator==(const allocator<_Tp>&, const allocator<_Tp>&)
122 { return true; }
124 template<typename _T1, typename _T2>
125 inline bool
126 operator!=(const allocator<_T1>&, const allocator<_T2>&)
127 { return false; }
129 template<typename _Tp>
130 inline bool
131 operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
132 { return false; }
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>;
140 #endif
142 // Undefine.
143 #undef __glibcxx_base_allocator
145 // To implement Option 3 of DR 431.
146 template<typename _Alloc, bool = __is_empty(_Alloc)>
147 struct __alloc_swap
148 { static void _S_do_it(_Alloc&, _Alloc&) { } };
150 template<typename _Alloc>
151 struct __alloc_swap<_Alloc, false>
153 static void
154 _S_do_it(_Alloc& __one, _Alloc& __two)
156 // Precondition: swappable allocators.
157 if (__one != __two)
158 swap(__one, __two);
162 // Optimize for stateless allocators.
163 template<typename _Alloc, bool = __is_empty(_Alloc)>
164 struct __alloc_neq
166 static bool
167 _S_do_it(const _Alloc&, const _Alloc&)
168 { return false; }
171 template<typename _Alloc>
172 struct __alloc_neq<_Alloc, false>
174 static bool
175 _S_do_it(const _Alloc& __one, const _Alloc& __two)
176 { return __one != __two; }
179 _GLIBCXX_END_NAMESPACE
181 #endif