PSP2SDK  dirty-f9e4f2d
The free SDK for PSP2
include/c++/ext/new_allocator.h
Go to the documentation of this file.
00001 // Allocator that wraps operator new -*- C++ -*-
00002 
00003 // Copyright (C) 2015 PSP2SDK Project
00004 // Modified for PSP2 by PSP2SDK Team
00005 
00006 // Copyright (C) 2001-2014 Free Software Foundation, Inc.
00007 //
00008 // This file is part of the GNU ISO C++ Library.  This library is free
00009 // software; you can redistribute it and/or modify it under the
00010 // terms of the GNU General Public License as published by the
00011 // Free Software Foundation; either version 3, or (at your option)
00012 // any later version.
00013 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 
00019 // Under Section 7 of GPL version 3, you are granted additional
00020 // permissions described in the GCC Runtime Library Exception, version
00021 // 3.1, as published by the Free Software Foundation.
00022 
00023 // You should have received a copy of the GNU General Public License and
00024 // a copy of the GCC Runtime Library Exception along with this program;
00025 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00026 // <http://www.gnu.org/licenses/>.
00027 
00032 #ifndef _NEW_ALLOCATOR_H
00033 #define _NEW_ALLOCATOR_H 1
00034 
00035 #include <bits/c++config.h>
00036 #include <new>
00037 #include <bits/functexcept.h>
00038 #include <bits/move.h>
00039 #if __cplusplus >= 201103L
00040 #include <type_traits>
00041 #endif
00042 
00043 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
00044 {
00045 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00046 
00047   using std::size_t;
00048   using std::ptrdiff_t;
00049 
00060   template<typename _Tp>
00061     class new_allocator
00062     {
00063     public:
00064       typedef size_t     size_type;
00065       typedef ptrdiff_t  difference_type;
00066       typedef _Tp*       pointer;
00067       typedef const _Tp* const_pointer;
00068       typedef _Tp&       reference;
00069       typedef const _Tp& const_reference;
00070       typedef _Tp        value_type;
00071 
00072       template<typename _Tp1>
00073         struct rebind
00074         { typedef new_allocator<_Tp1> other; };
00075 
00076 #if __cplusplus >= 201103L
00077       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00078       // 2103. propagate_on_container_move_assignment
00079       typedef std::true_type propagate_on_container_move_assignment;
00080 #endif
00081 
00082       new_allocator() _GLIBCXX_USE_NOEXCEPT { }
00083 
00084       new_allocator(const new_allocator&) _GLIBCXX_USE_NOEXCEPT { }
00085 
00086       template<typename _Tp1>
00087         new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { }
00088 
00089       ~new_allocator() _GLIBCXX_USE_NOEXCEPT { }
00090 
00091       pointer
00092       address(reference __x) const _GLIBCXX_NOEXCEPT
00093       { return std::__addressof(__x); }
00094 
00095       const_pointer
00096       address(const_reference __x) const _GLIBCXX_NOEXCEPT
00097       { return std::__addressof(__x); }
00098 
00099       // NB: __n is permitted to be 0.  The C++ standard says nothing
00100       // about what the return value is when __n == 0.
00101       pointer
00102       allocate(size_type __n, const void* = 0)
00103       { 
00104     if (__n > this->max_size())
00105       throw std::bad_alloc();
00106 
00107     return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
00108       }
00109 
00110       // __p is not permitted to be a null pointer.
00111       void
00112       deallocate(pointer __p, size_type)
00113       { ::operator delete(__p); }
00114 
00115       size_type
00116       max_size() const _GLIBCXX_USE_NOEXCEPT
00117       { return size_t(-1) / sizeof(_Tp); }
00118 
00119 #if __cplusplus >= 201103L
00120       template<typename _Up, typename... _Args>
00121         void
00122         construct(_Up* __p, _Args&&... __args)
00123     { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
00124 
00125       template<typename _Up>
00126         void 
00127         destroy(_Up* __p) { __p->~_Up(); }
00128 #else
00129       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00130       // 402. wrong new expression in [some_] allocator::construct
00131       void 
00132       construct(pointer __p, const _Tp& __val) 
00133       { ::new((void *)__p) _Tp(__val); }
00134 
00135       void 
00136       destroy(pointer __p) { __p->~_Tp(); }
00137 #endif
00138     };
00139 
00140   template<typename _Tp>
00141     inline bool
00142     operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
00143     { return true; }
00144   
00145   template<typename _Tp>
00146     inline bool
00147     operator!=(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
00148     { return false; }
00149 
00150 _GLIBCXX_END_NAMESPACE_VERSION
00151 } // namespace
00152 
00153 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines