1ffeaf689SAlexander Kabaev // Allocators -*- C++ -*- 2ffeaf689SAlexander Kabaev 3f8a1b7d9SAlexander Kabaev // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 4f8a1b7d9SAlexander Kabaev // Free Software Foundation, Inc. 5ffeaf689SAlexander Kabaev // 6ffeaf689SAlexander Kabaev // This file is part of the GNU ISO C++ Library. This library is free 7ffeaf689SAlexander Kabaev // software; you can redistribute it and/or modify it under the 8ffeaf689SAlexander Kabaev // terms of the GNU General Public License as published by the 9ffeaf689SAlexander Kabaev // Free Software Foundation; either version 2, or (at your option) 10ffeaf689SAlexander Kabaev // any later version. 11ffeaf689SAlexander Kabaev 12ffeaf689SAlexander Kabaev // This library is distributed in the hope that it will be useful, 13ffeaf689SAlexander Kabaev // but WITHOUT ANY WARRANTY; without even the implied warranty of 14ffeaf689SAlexander Kabaev // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15ffeaf689SAlexander Kabaev // GNU General Public License for more details. 16ffeaf689SAlexander Kabaev 17ffeaf689SAlexander Kabaev // You should have received a copy of the GNU General Public License along 18ffeaf689SAlexander Kabaev // with this library; see the file COPYING. If not, write to the Free 19f8a1b7d9SAlexander Kabaev // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20ffeaf689SAlexander Kabaev // USA. 21ffeaf689SAlexander Kabaev 22ffeaf689SAlexander Kabaev // As a special exception, you may use this file as part of a free software 23ffeaf689SAlexander Kabaev // library without restriction. Specifically, if other files instantiate 24ffeaf689SAlexander Kabaev // templates or use macros or inline functions from this file, or you compile 25ffeaf689SAlexander Kabaev // this file and link it with other files to produce an executable, this 26ffeaf689SAlexander Kabaev // file does not by itself cause the resulting executable to be covered by 27ffeaf689SAlexander Kabaev // the GNU General Public License. This exception does not however 28ffeaf689SAlexander Kabaev // invalidate any other reasons why the executable file might be covered by 29ffeaf689SAlexander Kabaev // the GNU General Public License. 30ffeaf689SAlexander Kabaev 31ffeaf689SAlexander Kabaev /* 32ffeaf689SAlexander Kabaev * Copyright (c) 1996-1997 33ffeaf689SAlexander Kabaev * Silicon Graphics Computer Systems, Inc. 34ffeaf689SAlexander Kabaev * 35ffeaf689SAlexander Kabaev * Permission to use, copy, modify, distribute and sell this software 36ffeaf689SAlexander Kabaev * and its documentation for any purpose is hereby granted without fee, 37ffeaf689SAlexander Kabaev * provided that the above copyright notice appear in all copies and 38ffeaf689SAlexander Kabaev * that both that copyright notice and this permission notice appear 39ffeaf689SAlexander Kabaev * in supporting documentation. Silicon Graphics makes no 40ffeaf689SAlexander Kabaev * representations about the suitability of this software for any 41ffeaf689SAlexander Kabaev * purpose. It is provided "as is" without express or implied warranty. 42ffeaf689SAlexander Kabaev */ 43ffeaf689SAlexander Kabaev 44ffeaf689SAlexander Kabaev /** @file allocator.h 45ffeaf689SAlexander Kabaev * This is an internal header file, included by other library headers. 46ffeaf689SAlexander Kabaev * You should not attempt to use it directly. 47ffeaf689SAlexander Kabaev */ 48ffeaf689SAlexander Kabaev 49ffeaf689SAlexander Kabaev #ifndef _ALLOCATOR_H 50ffeaf689SAlexander Kabaev #define _ALLOCATOR_H 1 51ffeaf689SAlexander Kabaev 52ffeaf689SAlexander Kabaev // Define the base class to std::allocator. 53ffeaf689SAlexander Kabaev #include <bits/c++allocator.h> 54ffeaf689SAlexander Kabaev 55f8a1b7d9SAlexander Kabaev #include <bits/cpp_type_traits.h> // for __is_empty 56f8a1b7d9SAlexander Kabaev 57f8a1b7d9SAlexander Kabaev _GLIBCXX_BEGIN_NAMESPACE(std) 58f8a1b7d9SAlexander Kabaev 59ffeaf689SAlexander Kabaev template<typename _Tp> 60ffeaf689SAlexander Kabaev class allocator; 61ffeaf689SAlexander Kabaev 62f8a1b7d9SAlexander Kabaev /// allocator<void> specialization. 63ffeaf689SAlexander Kabaev template<> 64ffeaf689SAlexander Kabaev class allocator<void> 65ffeaf689SAlexander Kabaev { 66ffeaf689SAlexander Kabaev public: 67ffeaf689SAlexander Kabaev typedef size_t size_type; 68ffeaf689SAlexander Kabaev typedef ptrdiff_t difference_type; 69ffeaf689SAlexander Kabaev typedef void* pointer; 70ffeaf689SAlexander Kabaev typedef const void* const_pointer; 71ffeaf689SAlexander Kabaev typedef void value_type; 72ffeaf689SAlexander Kabaev 73ffeaf689SAlexander Kabaev template<typename _Tp1> 74ffeaf689SAlexander Kabaev struct rebind 75ffeaf689SAlexander Kabaev { typedef allocator<_Tp1> other; }; 76ffeaf689SAlexander Kabaev }; 77ffeaf689SAlexander Kabaev 78ffeaf689SAlexander Kabaev /** 79ffeaf689SAlexander Kabaev * @brief The "standard" allocator, as per [20.4]. 80ffeaf689SAlexander Kabaev * 81f8a1b7d9SAlexander Kabaev * Further details: 82f8a1b7d9SAlexander Kabaev * http://gcc.gnu.org/onlinedocs/libstdc++/20_util/allocator.html 83ffeaf689SAlexander Kabaev */ 84ffeaf689SAlexander Kabaev template<typename _Tp> 85f8a1b7d9SAlexander Kabaev class allocator: public __glibcxx_base_allocator<_Tp> 86ffeaf689SAlexander Kabaev { 87ffeaf689SAlexander Kabaev public: 88ffeaf689SAlexander Kabaev typedef size_t size_type; 89ffeaf689SAlexander Kabaev typedef ptrdiff_t difference_type; 90ffeaf689SAlexander Kabaev typedef _Tp* pointer; 91ffeaf689SAlexander Kabaev typedef const _Tp* const_pointer; 92ffeaf689SAlexander Kabaev typedef _Tp& reference; 93ffeaf689SAlexander Kabaev typedef const _Tp& const_reference; 94ffeaf689SAlexander Kabaev typedef _Tp value_type; 95ffeaf689SAlexander Kabaev 96ffeaf689SAlexander Kabaev template<typename _Tp1> 97ffeaf689SAlexander Kabaev struct rebind 98ffeaf689SAlexander Kabaev { typedef allocator<_Tp1> other; }; 99ffeaf689SAlexander Kabaev throw()100ffeaf689SAlexander Kabaev allocator() throw() { } 101ffeaf689SAlexander Kabaev throw()102f8a1b7d9SAlexander Kabaev allocator(const allocator& __a) throw() 103f8a1b7d9SAlexander Kabaev : __glibcxx_base_allocator<_Tp>(__a) { } 104ffeaf689SAlexander Kabaev 105ffeaf689SAlexander Kabaev template<typename _Tp1> allocator(const allocator<_Tp1> &)106ffeaf689SAlexander Kabaev allocator(const allocator<_Tp1>&) throw() { } 107ffeaf689SAlexander Kabaev throw()108ffeaf689SAlexander Kabaev ~allocator() throw() { } 109ffeaf689SAlexander Kabaev 110ffeaf689SAlexander Kabaev // Inherit everything else. 111ffeaf689SAlexander Kabaev }; 112ffeaf689SAlexander Kabaev 113ffeaf689SAlexander Kabaev template<typename _T1, typename _T2> 114ffeaf689SAlexander Kabaev inline bool 115ffeaf689SAlexander Kabaev operator==(const allocator<_T1>&, const allocator<_T2>&) 116ffeaf689SAlexander Kabaev { return true; } 117ffeaf689SAlexander Kabaev 118*05a636f0SPedro F. Giffuni template<typename _Tp> 119*05a636f0SPedro F. Giffuni inline bool 120*05a636f0SPedro F. Giffuni operator==(const allocator<_Tp>&, const allocator<_Tp>&) 121*05a636f0SPedro F. Giffuni { return true; } 122*05a636f0SPedro F. Giffuni 123ffeaf689SAlexander Kabaev template<typename _T1, typename _T2> 124ffeaf689SAlexander Kabaev inline bool 125ffeaf689SAlexander Kabaev operator!=(const allocator<_T1>&, const allocator<_T2>&) 126ffeaf689SAlexander Kabaev { return false; } 127ffeaf689SAlexander Kabaev 128*05a636f0SPedro F. Giffuni template<typename _Tp> 129*05a636f0SPedro F. Giffuni inline bool 130*05a636f0SPedro F. Giffuni operator!=(const allocator<_Tp>&, const allocator<_Tp>&) 131*05a636f0SPedro F. Giffuni { return false; } 132*05a636f0SPedro F. Giffuni 133ffeaf689SAlexander Kabaev // Inhibit implicit instantiations for required instantiations, 134ffeaf689SAlexander Kabaev // which are defined via explicit instantiations elsewhere. 135ffeaf689SAlexander Kabaev // NB: This syntax is a GNU extension. 136ffeaf689SAlexander Kabaev #if _GLIBCXX_EXTERN_TEMPLATE 137ffeaf689SAlexander Kabaev extern template class allocator<char>; 138ffeaf689SAlexander Kabaev extern template class allocator<wchar_t>; 139ffeaf689SAlexander Kabaev #endif 140ffeaf689SAlexander Kabaev 141ffeaf689SAlexander Kabaev // Undefine. 142f8a1b7d9SAlexander Kabaev #undef __glibcxx_base_allocator 143f8a1b7d9SAlexander Kabaev 144f8a1b7d9SAlexander Kabaev // To implement Option 3 of DR 431. 145f8a1b7d9SAlexander Kabaev template<typename _Alloc, bool = std::__is_empty<_Alloc>::__value> 146f8a1b7d9SAlexander Kabaev struct __alloc_swap _S_do_it__alloc_swap147f8a1b7d9SAlexander Kabaev { static void _S_do_it(_Alloc&, _Alloc&) { } }; 148f8a1b7d9SAlexander Kabaev 149f8a1b7d9SAlexander Kabaev template<typename _Alloc> 150f8a1b7d9SAlexander Kabaev struct __alloc_swap<_Alloc, false> 151f8a1b7d9SAlexander Kabaev { 152f8a1b7d9SAlexander Kabaev static void 153f8a1b7d9SAlexander Kabaev _S_do_it(_Alloc& __one, _Alloc& __two) 154f8a1b7d9SAlexander Kabaev { 155f8a1b7d9SAlexander Kabaev // Precondition: swappable allocators. 156f8a1b7d9SAlexander Kabaev if (__one != __two) 157f8a1b7d9SAlexander Kabaev swap(__one, __two); 158f8a1b7d9SAlexander Kabaev } 159f8a1b7d9SAlexander Kabaev }; 160f8a1b7d9SAlexander Kabaev 161f8a1b7d9SAlexander Kabaev _GLIBCXX_END_NAMESPACE 162ffeaf689SAlexander Kabaev 163ffeaf689SAlexander Kabaev #endif 164