Usermode/libc++ - Override allocators to remove placement new call for primitive...
[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 /*
89         typedef T       value_type;
90         typedef T*      pointer;
91         typedef T&      reference;
92         typedef const T* const_pointer;
93         typedef const T&        const_reference;
94         typedef size_t  size_type;
95         typedef ptrdiff_t       difference_type;
96
97         template <class Type>
98         struct rebind
99         {
100                 typedef allocator<Type> other;
101         };
102         
103         allocator_noconstruct() throw() {
104         }
105         allocator_noconstruct(const allocator_noconstruct& alloc __attribute__((unused))) throw() {
106         }
107         template <class U>
108         allocator_noconstruct(const allocator_noconstruct<U>& alloc) throw() {
109         }
110         ~allocator_noconstruct() throw() {
111         }
112
113         pointer address(reference x) const {
114                 return &x;
115         }
116         const_pointer address(const_reference x) const {
117                 return &x;
118         }
119         pointer allocate(size_type n, const void* hint=0) {
120                 hint = hint;
121                 return static_cast<pointer>( ::operator new (n * sizeof(value_type)) );
122         }
123         void deallocate(pointer p, size_type n) {
124                 n=n;
125                 ::operator delete(p);
126         }
127         size_type max_size() {
128                 return ((size_type)-1) / sizeof(value_type);
129         }
130 */
131
132         void construct( typename allocator_real<T>::pointer p, typename allocator_real<T>::const_reference val ) {
133                 *p = val;
134         }
135         // C++11
136         #if _CXX11_AVAIL
137         template<class U, class... Args>
138         void construct( U* p, Args&&... args ) {
139         }
140         #endif
141         void destroy(typename allocator_real<T>::pointer p) {
142         }
143 };
144
145 };
146
147 template <class T>
148 class allocator:
149         public _bits::allocator_real<T>
150 {
151 };
152
153 template <>
154 class allocator<unsigned char>:
155         public _bits::allocator_noconstruct<unsigned char>
156 {
157 };
158 template <>
159 class allocator<unsigned long>:
160         public _bits::allocator_noconstruct<unsigned long>
161 {
162 };
163
164 };
165
166 #endif
167
168 // vim: ft=cpp
169

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