00001 // Allocators -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // You should have received a copy of the GNU General Public License along 00018 // with this library; see the file COPYING. If not, write to the Free 00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00020 // USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 /* 00032 * Copyright (c) 1996-1997 00033 * Silicon Graphics Computer Systems, Inc. 00034 * 00035 * Permission to use, copy, modify, distribute and sell this software 00036 * and its documentation for any purpose is hereby granted without fee, 00037 * provided that the above copyright notice appear in all copies and 00038 * that both that copyright notice and this permission notice appear 00039 * in supporting documentation. Silicon Graphics makes no 00040 * representations about the suitability of this software for any 00041 * purpose. It is provided "as is" without express or implied warranty. 00042 */ 00043 00044 /** @file allocator.h 00045 * This is an internal header file, included by other library headers. 00046 * You should not attempt to use it directly. 00047 */ 00048 00049 #ifndef _ALLOCATOR_H 00050 #define _ALLOCATOR_H 1 00051 00052 // Define the base class to std::allocator. 00053 #include <bits/c++allocator.h> 00054 00055 #include <bits/cpp_type_traits.h> // for __is_empty 00056 00057 _GLIBCXX_BEGIN_NAMESPACE(std) 00058 00059 template<typename _Tp> 00060 class allocator; 00061 00062 /// allocator<void> specialization. 00063 template<> 00064 class allocator<void> 00065 { 00066 public: 00067 typedef size_t size_type; 00068 typedef ptrdiff_t difference_type; 00069 typedef void* pointer; 00070 typedef const void* const_pointer; 00071 typedef void value_type; 00072 00073 template<typename _Tp1> 00074 struct rebind 00075 { typedef allocator<_Tp1> other; }; 00076 }; 00077 00078 /** 00079 * @brief The "standard" allocator, as per [20.4]. 00080 * 00081 * Further details: 00082 * http://gcc.gnu.org/onlinedocs/libstdc++/20_util/allocator.html 00083 */ 00084 template<typename _Tp> 00085 class allocator: public __glibcxx_base_allocator<_Tp> 00086 { 00087 public: 00088 typedef size_t size_type; 00089 typedef ptrdiff_t difference_type; 00090 typedef _Tp* pointer; 00091 typedef const _Tp* const_pointer; 00092 typedef _Tp& reference; 00093 typedef const _Tp& const_reference; 00094 typedef _Tp value_type; 00095 00096 template<typename _Tp1> 00097 struct rebind 00098 { typedef allocator<_Tp1> other; }; 00099 00100 allocator() throw() { } 00101 00102 allocator(const allocator& __a) throw() 00103 : __glibcxx_base_allocator<_Tp>(__a) { } 00104 00105 template<typename _Tp1> 00106 allocator(const allocator<_Tp1>&) throw() { } 00107 00108 ~allocator() throw() { } 00109 00110 // Inherit everything else. 00111 }; 00112 00113 template<typename _T1, typename _T2> 00114 inline bool 00115 operator==(const allocator<_T1>&, const allocator<_T2>&) 00116 { return true; } 00117 00118 template<typename _T1, typename _T2> 00119 inline bool 00120 operator!=(const allocator<_T1>&, const allocator<_T2>&) 00121 { return false; } 00122 00123 // Inhibit implicit instantiations for required instantiations, 00124 // which are defined via explicit instantiations elsewhere. 00125 // NB: This syntax is a GNU extension. 00126 #if _GLIBCXX_EXTERN_TEMPLATE 00127 extern template class allocator<char>; 00128 extern template class allocator<wchar_t>; 00129 #endif 00130 00131 // Undefine. 00132 #undef __glibcxx_base_allocator 00133 00134 // To implement Option 3 of DR 431. 00135 template<typename _Alloc, bool = std::__is_empty<_Alloc>::__value> 00136 struct __alloc_swap 00137 { static void _S_do_it(_Alloc&, _Alloc&) { } }; 00138 00139 template<typename _Alloc> 00140 struct __alloc_swap<_Alloc, false> 00141 { 00142 static void 00143 _S_do_it(_Alloc& __one, _Alloc& __two) 00144 { 00145 // Precondition: swappable allocators. 00146 if (__one != __two) 00147 swap(__one, __two); 00148 } 00149 }; 00150 00151 _GLIBCXX_END_NAMESPACE 00152 00153 #endif