Changeset 08c1df0 in mainline for uspace/lib/cpp/include/impl/memory.hpp
- Timestamp:
- 2018-07-05T21:41:24Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f31ea60
- Parents:
- ca8d393
- git-author:
- Dzejrou <dzejrou@…> (2018-05-16 17:20:56)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:24)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/memory.hpp
rca8d393 r08c1df0 36 36 #include <internal/memory/type_getters.hpp> 37 37 #include <iterator> 38 #include <limits> 38 39 #include <new> 39 40 #include <type_traits> … … 131 132 using allocator_type = Alloc; 132 133 133 using value_type = typename Alloc::value_type; 134 using pointer = typename aux::get_pointer<Alloc>::type; 135 using const_pointer = typename aux::get_const_pointer<Alloc, pointer>::type; 136 // TODO: fix void pointer typedefs 137 /* using void_pointer = typename aux::get_void_pointer<Alloc, pointer>::type; */ 138 /* using const_void_pointer = typename aux::get_const_void_pointer<Alloc, pointer>::type; */ 139 using void_pointer = void*; 140 using const_void_pointer = const void*; 141 using difference_type = typename aux::get_difference_type<Alloc, pointer>::type; 142 using size_type = typename aux::get_size_type<Alloc, difference_type>::type; 143 144 using propagate_on_container_copy_assignment = typename aux::get_copy_propagate<Alloc>::type; 145 using propagate_on_container_move_assignment = typename aux::get_move_propagate<Alloc>::type; 146 using propagate_on_container_swap = typename aux::get_swap_propagate<Alloc>::type; 147 using is_always_equal = typename aux::get_always_equal<Alloc>::type; 134 using value_type = typename Alloc::value_type; 135 using pointer = typename aux::alloc_get_pointer<Alloc>::type; 136 using const_pointer = typename aux::alloc_get_const_pointer<Alloc, pointer>::type; 137 using void_pointer = typename aux::alloc_get_void_pointer<Alloc, pointer>::type; 138 using const_void_pointer = typename aux::alloc_get_const_void_pointer<Alloc, pointer>::type; 139 using difference_type = typename aux::alloc_get_difference_type<Alloc, pointer>::type; 140 using size_type = typename aux::alloc_get_size_type<Alloc, difference_type>::type; 141 142 using propagate_on_container_copy_assignment = typename aux::alloc_get_copy_propagate<Alloc>::type; 143 using propagate_on_container_move_assignment = typename aux::alloc_get_move_propagate<Alloc>::type; 144 using propagate_on_container_swap = typename aux::alloc_get_swap_propagate<Alloc>::type; 145 using is_always_equal = typename aux::alloc_get_always_equal<Alloc>::type; 148 146 149 147 template<class T> 150 using rebind_alloc = typename aux:: get_rebind_args<Alloc, T>;148 using rebind_alloc = typename aux::alloc_get_rebind_alloc<Alloc, T>; 151 149 152 150 template<class T> … … 159 157 160 158 static pointer allocate(Alloc& alloc, size_type n, const_void_pointer hint) 161 { // TODO: this when it's well formed, otherwise alloc.allocate(n) 162 return alloc.allocate(n, hint); 159 { 160 if constexpr (aux::alloc_has_hint_allocate<Alloc, size_type, const_void_pointer>::value) 161 return alloc.allocate(n, hint); 162 else 163 return alloc.allocate(n); 163 164 } 164 165 … … 171 172 static void construct(Alloc& alloc, T* ptr, Args&&... args) 172 173 { 173 // TODO: why wasn't this implemented? check standard for remarks 174 alloc.construct(ptr, forward<Args>(args)...); 174 if constexpr (aux::alloc_has_construct<Alloc, T, Args...>::value) 175 alloc.construct(ptr, forward<Args>(args)...); 176 else 177 ::new(static_cast<void*>(ptr)) T(forward<Args>(args)...); 175 178 } 176 179 … … 178 181 static void destroy(Alloc& alloc, T* ptr) 179 182 { 180 // TODO: implement 183 if constexpr (aux::alloc_has_destroy<Alloc, T>::value) 184 alloc.destroy(ptr); 185 else 186 ptr->~T(); 181 187 } 182 188 183 189 static size_type max_size(const Alloc& alloc) noexcept 184 190 { 185 // TODO: implement 186 return 0; 191 if constexpr (aux::alloc_has_max_size<Alloc>::value) 192 return alloc.max_size(); 193 else 194 return numeric_limits<size_type>::max(); 187 195 } 188 196 189 197 static Alloc select_on_container_copy_construction(const Alloc& alloc) 190 198 { 191 // TODO: implement 192 return Alloc{}; 199 if constexpr (aux::alloc_has_select<Alloc>::value) 200 return alloc.select_on_container_copy_construction(); 201 else 202 return alloc; 193 203 } 194 204 }; … … 246 256 template<class U> 247 257 allocator(const allocator<U>&) noexcept 248 { 249 // TODO: implement 250 } 258 { /* DUMMY BODY */ } 251 259 252 260 ~allocator() = default; … … 262 270 } 263 271 264 pointer allocate(size_type n, allocator<void>::const_pointer hint = 0) 265 { 266 /** 267 * Note: The usage of hint is unspecified. 268 * TODO: Check HelenOS hint allocation capabilities. 269 * TODO: assert that n < max_size() 270 */ 272 pointer allocate(size_type n, allocator<void>::const_pointer = 0) 273 { 271 274 return static_cast<pointer>(::operator new(n * sizeof(value_type))); 272 275 } … … 278 281 279 282 size_type max_size() const noexcept 280 { // TODO: implement, max argument to allocate281 return 0xFFFFFFFF;283 { 284 return numeric_limits<size_type>::max(); 282 285 } 283 286
Note:
See TracChangeset
for help on using the changeset viewer.