Ignore:
Timestamp:
2018-07-05T21:41:24Z (7 years ago)
Author:
Dzejrou <dzejrou@…>
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)
Message:

cpp: fixed typedefs in allocator_traits, finished type getters and implemented conditional calls in allocator_traits

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/memory.hpp

    rca8d393 r08c1df0  
    3636#include <internal/memory/type_getters.hpp>
    3737#include <iterator>
     38#include <limits>
    3839#include <new>
    3940#include <type_traits>
     
    131132        using allocator_type = Alloc;
    132133
    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;
    148146
    149147        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>;
    151149
    152150        template<class T>
     
    159157
    160158        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);
    163164        }
    164165
     
    171172        static void construct(Alloc& alloc, T* ptr, Args&&... args)
    172173        {
    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)...);
    175178        }
    176179
     
    178181        static void destroy(Alloc& alloc, T* ptr)
    179182        {
    180             // TODO: implement
     183            if constexpr (aux::alloc_has_destroy<Alloc, T>::value)
     184                alloc.destroy(ptr);
     185            else
     186                ptr->~T();
    181187        }
    182188
    183189        static size_type max_size(const Alloc& alloc) noexcept
    184190        {
    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();
    187195        }
    188196
    189197        static Alloc select_on_container_copy_construction(const Alloc& alloc)
    190198        {
    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;
    193203        }
    194204    };
     
    246256            template<class U>
    247257            allocator(const allocator<U>&) noexcept
    248             {
    249                 // TODO: implement
    250             }
     258            { /* DUMMY BODY */ }
    251259
    252260            ~allocator() = default;
     
    262270            }
    263271
    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            {
    271274                return static_cast<pointer>(::operator new(n * sizeof(value_type)));
    272275            }
     
    278281
    279282            size_type max_size() const noexcept
    280             { // TODO: implement, max argument to allocate
    281                 return 0xFFFFFFFF;
     283            {
     284                return numeric_limits<size_type>::max();
    282285            }
    283286
Note: See TracChangeset for help on using the changeset viewer.