allocator.h

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

Generated on Tue Feb 2 16:55:43 2010 for GNU C++ STL by  doxygen 1.4.7