1
/* Copyright (C) 2004 Garrett A. Kajmowicz
3
This file is part of the uClibc++ Library.
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#include <iterator_base>
27
#ifndef HEADER_STD_MEMORY
28
#define HEADER_STD_MEMORY 1
30
#pragma GCC visibility push(default)
34
template <class T> class allocator;
35
// Specialize for void:
37
template <> class _UCXXEXPORT allocator<void> {
39
typedef void* pointer;
40
typedef const void* const_pointer;
41
typedef void value_type;
42
template <class U> struct rebind { typedef allocator<U> other; };
45
template <class T> class _UCXXEXPORT allocator{
48
typedef size_t size_type;
49
typedef ptrdiff_t difference_type;
52
typedef const T* const_pointer;
55
typedef const T& const_reference;
57
pointer address(reference r) const { return &r; }
58
const_pointer address(const_reference r) const { return &r; }
61
template <class U> allocator(const allocator<U>& ) throw();
62
~allocator() throw(){}
65
pointer allocate(size_type n, typename allocator<void>::const_pointer = 0){
66
return (T*)(::operator new( n * sizeof(T) ));
68
void deallocate(pointer p, size_type){
72
//Use placement new to engage the constructor
73
void construct(pointer p, const T& val) { new((void*)p) T(val); }
74
void destroy(pointer p){ ((T*)p)->~T(); } //Call destructor
76
size_type max_size() const throw();
77
template<class U> struct rebind { typedef allocator<U> other; };
81
template <class Out, class T> class _UCXXEXPORT raw_storage_iterator
82
: public iterator<output_iterator_tag, void, void, void, void>
87
explicit raw_storage_iterator(Out pp) : p (pp) { }
88
raw_storage_iterator & operator*() { return *this; }
89
raw_storage_iterator & operator=(const T& val) {
95
raw_storage_iterator & operator++() { ++p; return *this; }
96
raw_storage_iterator operator++(int) {
97
raw_storage_iterator t = *this;
103
template <class T> _UCXXEXPORT pair<T*, ptrdiff_t> get_temporary_buffer(ptrdiff_t n){
104
pair<T*, ptrdiff_t> retval;
105
retval.first = static_cast<T*>(malloc(n * sizeof(T)));
106
if(retval.first == 0){
114
template <class T> _UCXXEXPORT void return_temporary_buffer(T* p){
119
template <class T> class _UCXXEXPORT auto_ptr{
123
template <class Y> struct auto_ptr_ref{
129
typedef T element_type;
131
explicit auto_ptr(T* p =0) throw() : object(p){ }
132
auto_ptr(auto_ptr& p) throw() : object(p.release()){ }
133
auto_ptr(auto_ptr_ref<T> r) throw() : object(r.p){
136
template<class Y> auto_ptr(auto_ptr<Y>& p) throw() : object(p.release()){ }
137
auto_ptr& operator=(auto_ptr& p) throw(){
142
object = p.release();
145
template<class Y> auto_ptr& operator=(auto_ptr<Y>& p) throw(){
150
object = p.release();
157
T& operator*() const throw(){
160
T* operator->() const throw(){
163
T* get() const throw(){
166
T* release() throw(){
171
void reset(T * p=0) throw(){
177
template<class Y> operator auto_ptr_ref<Y>() throw(){
178
auto_ptr_ref<Y> retval;
183
template<class Y> operator auto_ptr<Y>() throw(){
184
auto_ptr<Y> retval(object);
193
#pragma GCC visibility pop