Changeset 08c1df0 in mainline
- 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)
- Location:
- uspace/lib/cpp/include
- Files:
-
- 2 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 -
uspace/lib/cpp/include/internal/memory/type_getters.hpp
rca8d393 r08c1df0 98 98 99 99 template<class T, class = void> 100 struct get_pointer: aux::type_is<typename T::value_type*>101 { /* DUMMY BODY */ }; 102 103 template<class T> 104 struct get_pointer<T, void_t<typename T::pointer>>100 struct alloc_get_pointer: aux::type_is<typename T::value_type*> 101 { /* DUMMY BODY */ }; 102 103 template<class T> 104 struct alloc_get_pointer<T, void_t<typename T::pointer>> 105 105 : aux::type_is<typename T::pointer> 106 106 { /* DUMMY BODY */ }; 107 107 108 108 template<class T, class Ptr, class = void> 109 struct get_const_pointer109 struct alloc_get_const_pointer 110 110 : aux::type_is<typename pointer_traits<Ptr>::template rebind<const typename T::value_type>> 111 111 { /* DUMMY BODY */ }; 112 112 113 113 template<class T, class Ptr> 114 struct get_const_pointer<T, Ptr, void_t<typename T::const_pointer>>114 struct alloc_get_const_pointer<T, Ptr, void_t<typename T::const_pointer>> 115 115 : aux::type_is<typename T::const_pointer> 116 116 { /* DUMMY BODY */ }; 117 117 118 118 template<class T, class Ptr, class = void> 119 struct get_void_pointer119 struct alloc_get_void_pointer 120 120 : aux::type_is<typename pointer_traits<Ptr>::template rebind<void>> 121 121 { /* DUMMY BODY */ }; 122 122 123 123 template<class T, class Ptr> 124 struct get_void_pointer<T, Ptr, void_t<typename T::void_pointer>>124 struct alloc_get_void_pointer<T, Ptr, void_t<typename T::void_pointer>> 125 125 : aux::type_is<typename T::void_pointer> 126 126 { /* DUMMY BODY */ }; 127 127 128 128 template<class T, class Ptr, class = void> 129 struct get_const_void_pointer129 struct alloc_get_const_void_pointer 130 130 : aux::type_is<typename pointer_traits<Ptr>::template rebind<const void>> 131 131 { /* DUMMY BODY */ }; 132 132 133 133 template<class T, class Ptr> 134 struct get_const_void_pointer<T, Ptr, void_t<typename T::const_void_pointer>>134 struct alloc_get_const_void_pointer<T, Ptr, void_t<typename T::const_void_pointer>> 135 135 : aux::type_is<typename T::const_void_pointer> 136 136 { /* DUMMY BODY */ }; 137 137 138 138 template<class T, class Ptr, class = void> 139 struct get_difference_type139 struct alloc_get_difference_type 140 140 : aux::type_is<typename pointer_traits<Ptr>::difference_type> 141 141 { /* DUMMY BODY */ }; 142 142 143 143 template<class T, class Ptr> 144 struct get_difference_type<T, Ptr, void_t<typename T::difference_type>>144 struct alloc_get_difference_type<T, Ptr, void_t<typename T::difference_type>> 145 145 : aux::type_is<typename T::difference_type> 146 146 { /* DUMMY BODY */ }; 147 147 148 148 template<class T, class Difference, class = void> 149 struct get_size_type: aux::type_is<make_unsigned_t<Difference>>149 struct alloc_get_size_type: aux::type_is<make_unsigned_t<Difference>> 150 150 { /* DUMMY BODY */ }; 151 151 152 152 template<class T, class Difference> 153 struct get_size_type<T, Difference, void_t<typename T::size_type>>153 struct alloc_get_size_type<T, Difference, void_t<typename T::size_type>> 154 154 : aux::type_is<typename T::size_type> 155 155 { /* DUMMY BODY */ }; 156 156 157 157 template<class T, class = void> 158 struct get_copy_propagate: aux::type_is<false_type>159 { /* DUMMY BODY */ }; 160 161 template<class T> 162 struct get_copy_propagate<T, void_t<typename T::propagate_on_container_copy_assignment>>158 struct alloc_get_copy_propagate: aux::type_is<false_type> 159 { /* DUMMY BODY */ }; 160 161 template<class T> 162 struct alloc_get_copy_propagate<T, void_t<typename T::propagate_on_container_copy_assignment>> 163 163 : aux::type_is<typename T::propagate_on_container_copy_assignment> 164 164 { /* DUMMY BODY */ }; 165 165 166 166 template<class T, class = void> 167 struct get_move_propagate: aux::type_is<false_type>168 { /* DUMMY BODY */ }; 169 170 template<class T> 171 struct get_move_propagate<T, void_t<typename T::propagate_on_container_move_assignment>>167 struct alloc_get_move_propagate: aux::type_is<false_type> 168 { /* DUMMY BODY */ }; 169 170 template<class T> 171 struct alloc_get_move_propagate<T, void_t<typename T::propagate_on_container_move_assignment>> 172 172 : aux::type_is<typename T::propagate_on_container_move_assignment> 173 173 { /* DUMMY BODY */ }; 174 174 175 175 template<class T, class = void> 176 struct get_swap_propagate: aux::type_is<false_type>177 { /* DUMMY BODY */ }; 178 179 template<class T> 180 struct get_swap_propagate<T, void_t<typename T::propagate_on_container_swap>>176 struct alloc_get_swap_propagate: aux::type_is<false_type> 177 { /* DUMMY BODY */ }; 178 179 template<class T> 180 struct alloc_get_swap_propagate<T, void_t<typename T::propagate_on_container_swap>> 181 181 : aux::type_is<typename T::propagate_on_container_swap> 182 182 { /* DUMMY BODY */ }; 183 183 184 184 template<class T, class = void> 185 struct get_always_equal: aux::type_is<typename is_empty<T>::type>186 { /* DUMMY BODY */ }; 187 188 template<class T> 189 struct get_always_equal<T, void_t<typename T::is_always_equal>>185 struct alloc_get_always_equal: aux::type_is<typename is_empty<T>::type> 186 { /* DUMMY BODY */ }; 187 188 template<class T> 189 struct alloc_get_always_equal<T, void_t<typename T::is_always_equal>> 190 190 : aux::type_is<typename T::is_always_equal> 191 191 { /* DUMMY BODY */ }; 192 192 193 193 template<class Alloc, class T, class = void> 194 struct get_rebind_other194 struct alloc_get_rebind_alloc 195 195 { /* DUMMY BODY */ }; 196 196 197 197 template<class Alloc, class T> 198 struct get_rebind_other<Alloc, T, void_t<typename Alloc::template rebind<T>::other>>198 struct alloc_get_rebind_alloc<Alloc, T, void_t<typename Alloc::template rebind<T>::other>> 199 199 : aux::type_is<typename Alloc::template rebind<T>::other> 200 200 { /* DUMMY BODY */ }; 201 201 202 /* TODO: How am I suppose to do this?! 203 template<template<class T, class... Args> class Alloc> 204 struct get_rebind_args; 205 */ 202 template<template <class, class...> class Alloc, class U, class... Args, class T> 203 struct alloc_get_rebind_alloc<Alloc<U, Args...>, T> 204 : aux::type_is<Alloc<T, Args...>> 205 { /* DUMMY BODY */ }; 206 207 /** 208 * These metafunctions are used to check whether an expression 209 * is well-formed for the static functions of allocator_traits: 210 */ 211 212 template<class Alloc, class Size, class ConstVoidPointer, class = void> 213 struct alloc_has_hint_allocate: false_type 214 { /* DUMMY BODY */ }; 215 216 template<class Alloc, class Size, class ConstVoidPointer> 217 struct alloc_has_hint_allocate< 218 Alloc, Size, ConstVoidPointer, void_t< 219 decltype(declval<Alloc>().alloc(declval<Size>(), declval<ConstVoidPointer>())) 220 > 221 >: true_type 222 { /* DUMMY BODY */ }; 223 224 template<class, class Alloc, class T, class... Args> 225 struct alloc_has_construct_impl: false_type 226 { /* DUMMY BODY */ }; 227 228 template<class Alloc, class T, class... Args> 229 struct alloc_has_construct_impl< 230 void_t<decltype(declval<Alloc>().construct(declval<T*>(), forward<Args>(declval<Args>())...))>, 231 Alloc, T, Args... 232 >: true_type 233 { /* DUMMY BODY */ }; 234 235 template<class Alloc, class T, class = void> 236 struct alloc_has_destroy: false_type 237 { /* DUMMY BODY */ }; 206 238 207 239 template<class Alloc, class T> 208 struct get_rebind_args: aux::type_is<typename get_rebind_other<Alloc, T>::type> 240 struct alloc_has_destroy<Alloc, T, void_t<decltype(declval<Alloc>().destroy(declval<T>()))>> 241 : true_type 242 { /* DUMMY BODY */ }; 243 244 template<class Alloc, class T, class... Args> 245 struct alloc_has_construct 246 : alloc_has_construct_impl<void_t<>, Alloc, T, Args...> 247 { /* DUMMY BODY */ }; 248 249 template<class Alloc, class = void> 250 struct alloc_has_max_size: false_type 251 { /* DUMMY BODY */ }; 252 253 template<class Alloc> 254 struct alloc_has_max_size<Alloc, void_t<decltype(declval<Alloc>().max_size())>> 255 : true_type 256 { /* DUMMY BODY */ }; 257 258 template<class Alloc, class = void> 259 struct alloc_has_select: false_type 260 { /* DUMMY BODY */ }; 261 262 template<class Alloc> 263 struct alloc_has_select< 264 Alloc, void_t< 265 decltype(declval<Alloc>().select_on_container_copy_construction()) 266 > 267 >: true_type 209 268 { /* DUMMY BODY */ }; 210 269 }
Note:
See TracChangeset
for help on using the changeset viewer.