1608a3c72ed36f273230782e84a58104be4c1a3b
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / include_exp / allocator
1 /*
2  * Acess2 C++ Library
3  * - By John Hodge (thePowersGang)
4  *
5  * string (header)
6  * - C++'s String type
7  */
8 #ifndef _LIBCXX_ALLOCATOR_
9 #define _LIBCXX_ALLOCATOR_
10
11 #include "_libcxx_helpers.h"
12
13 #include "new"
14 #include "cstddef"
15 #include "utility"
16
17 namespace std {
18
19 template <class T> class allocator;
20
21 namespace _bits {
22
23 template <class T>
24 class allocator_real
25 {
26 public:
27         typedef T       value_type;
28         typedef T*      pointer;
29         typedef T&      reference;
30         typedef const T* const_pointer;
31         typedef const T&        const_reference;
32         typedef size_t  size_type;
33         typedef ptrdiff_t       difference_type;
34         
35         template <class Type>
36         struct rebind
37         {
38                 typedef allocator<Type> other;
39         };
40         
41         allocator_real() throw() {
42         }
43         allocator_real(const allocator_real& alloc __attribute__((unused))) throw() {
44         }
45         template <class U>
46         allocator_real(const allocator_real<U>& alloc) throw() {
47         }
48         ~allocator_real() throw() {
49         }
50         
51         pointer address(reference x) const {
52                 return &x;
53         }
54         const_pointer address(const_reference x) const {
55                 return &x;
56         }
57         pointer allocate(size_type n, const void* hint=0) {
58                 hint = hint;
59                 return static_cast<pointer>( ::operator new (n * sizeof(value_type)) );
60         }
61         void deallocate(pointer p, size_type n) {
62                 n=n;
63                 ::operator delete(p);
64         }
65         size_type max_size() {
66                 return ((size_type)-1) / sizeof(value_type);
67         }
68         void construct( pointer p, const_reference val ) {
69                 new ((void*)p) value_type (val);
70         }
71         // C++11
72         #if _CXX11_AVAIL
73         template<class U, class... Args>
74         void construct( U* p, Args&&... args ) {
75                 ::new ((void*)p) U (::std::forward<Args>(args)...);
76         }
77         #endif
78         void destroy(pointer p) {
79                 p->~value_type();
80         }
81 };
82
83 template <class T>
84 class allocator_noconstruct:
85         public ::std::_bits::allocator_real<T>
86 {
87 public:
88         void construct( typename allocator_real<T>::pointer p, typename allocator_real<T>::const_reference val ) {
89                 *p = val;
90         }
91         void destroy(typename allocator_real<T>::pointer p) {
92         }
93 };
94
95 };
96
97 template <class T>
98 class allocator:
99         public _bits::allocator_real<T>
100 {
101 };
102
103 #if 1
104 template <>
105 class allocator<unsigned char>:
106         public _bits::allocator_noconstruct<unsigned char>
107 {
108 };
109 template <>
110 class allocator<unsigned long>:
111         public _bits::allocator_noconstruct<unsigned long>
112 {
113 };
114 #endif
115
116 };
117
118 #endif
119
120 // vim: ft=cpp
121

UCC git Repository :: git.ucc.asn.au