Changeset de00da5 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:23Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6a3a64f
Parents:
09e02ee
git-author:
Dzejrou <dzejrou@…> (2018-05-09 23:42:29)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
Message:

cpp: fixed enable_if usage, added payload_tag that allows us to properly construct smart pointers from payloads

Location:
uspace/lib/cpp/include/internal/memory
Files:
3 edited

Legend:

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

    r09e02ee rde00da5  
    4949    using refcount_t = long;
    5050
     51    /**
     52     * This allows us to construct shared_ptr from
     53     * a payload pointer in make_shared etc.
     54     */
     55    struct payload_tag_t
     56    { /* DUMMY BODY */ };
     57
     58    inline constexpr payload_tag_t payload_tag{};
     59
    5160    template<class D, class T>
    5261    void use_payload_deleter(D* deleter, T* data)
  • uspace/lib/cpp/include/internal/memory/shared_ptr.hpp

    r09e02ee rde00da5  
    7676            template<class U>
    7777            explicit shared_ptr(
    78                 enable_if_t<is_convertible_v<U*, element_type*>, U*> ptr
     78                U* ptr,
     79                enable_if_t<is_convertible_v<U*, element_type*>>* = nullptr
    7980            )
    8081                : payload_{}, data_{ptr}
     
    9495            template<class U, class D>
    9596            shared_ptr(
    96                 enable_if_t<is_convertible_v<U*, element_type*>, U*> ptr, D deleter
     97                U* ptr, D deleter,
     98                enable_if_t<is_convertible_v<U*, element_type*>>* = nullptr
    9799            )
    98100                : shared_ptr{}
     
    112114            template<class U, class D, class A>
    113115            shared_ptr(
    114                 enable_if_t<is_convertible_v<U*, element_type*>, U*> ptr,
    115                 D deleter, A
     116                U* ptr, D deleter, A,
     117                enable_if_t<is_convertible_v<U*, element_type*>>* = nullptr
    116118            )
    117119                : shared_ptr{}
     
    141143            template<class U>
    142144            shared_ptr(
    143                 enable_if_t<is_convertible_v<U*, element_type*>, const shared_ptr<U>&> other,
    144                 element_type* ptr
     145                const shared_ptr<U>& other, element_type* ptr,
     146                enable_if_t<is_convertible_v<U*, element_type*>>* = nullptr
    145147            )
    146148                : payload_{other.payload_}, data_{ptr}
     
    159161            template<class U>
    160162            shared_ptr(
    161                 enable_if_t<is_convertible_v<U*, element_type*>, const shared_ptr<U>&> other
     163                const shared_ptr<U>& other,
     164                enable_if_t<is_convertible_v<U*, element_type*>>* = nullptr
    162165            )
    163166                : payload_{other.payload_}, data_{other.data_}
     
    176179            template<class U>
    177180            shared_ptr(
    178                 enable_if_t<is_convertible_v<U*, element_type*>, shared_ptr<U>&&> other
     181                shared_ptr<U>&& other,
     182                enable_if_t<is_convertible_v<U*, element_type*>>* = nullptr
    179183            )
    180184                : payload_{move(other.payload_)}, data_{move(other.data_)}
     
    186190            template<class U>
    187191            explicit shared_ptr(
    188                 enable_if_t<is_convertible_v<U*, element_type*>, const weak_ptr<U>&> other
     192                const weak_ptr<U>& other,
     193                enable_if_t<is_convertible_v<U*, element_type*>>* = nullptr
    189194            )
    190195            {
     
    196201            template<class U, class D>
    197202            shared_ptr(
     203                unique_ptr<U, D>&& other,
    198204                enable_if_t<
    199205                    is_convertible_v<
    200206                        typename unique_ptr<U, D>::pointer,
    201207                        element_type*
    202                     >,
    203                     unique_ptr<U, D>&&
    204                 > other
     208                    >
     209                >* = nullptr
    205210            ) // TODO: if D is a reference type, it should be ref(other.get_deleter())
    206211                : shared_ptr{other.release(), other.get_deleter()}
     
    238243
    239244            template<class U>
    240             shared_ptr& operator=(
    241                 enable_if_t<is_convertible_v<U*, element_type*>, const shared_ptr<U>&> rhs
    242             ) noexcept
     245            enable_if_t<is_convertible_v<U*, element_type*>, shared_ptr>&
     246            operator=(const shared_ptr<U>& rhs) noexcept
    243247            {
    244248                if (rhs.payload_)
     
    261265
    262266            template<class U>
    263             shared_ptr& operator=(
    264                 enable_if_t<is_convertible_v<U*, element_type*>, shared_ptr<U>&&> rhs
    265             ) noexcept
     267            shared_ptr& operator=(shared_ptr<U>&& rhs) noexcept
    266268            {
    267269                shared_ptr{move(rhs)}.swap(*this);
     
    364366            element_type* data_;
    365367
    366             shared_ptr(aux::shared_payload_base<element_type>* payload)
     368            shared_ptr(aux::payload_tag_t, aux::shared_payload_base<element_type>* payload)
    367369                : payload_{payload}, data_{payload->get()}
    368370            { /* DUMMY BODY */ }
     
    409411    {
    410412        return shared_ptr<T>{
     413            aux::payload_tag,
    411414            new aux::shared_payload<T>{forward<Args>(args)...}
    412415        };
     
    417420    {
    418421        return shared_ptr<T>{
     422            aux::payload_tag,
    419423            new aux::shared_payload<T>{allocator_arg, A{alloc}, forward<Args>(args)...}
    420424        };
  • uspace/lib/cpp/include/internal/memory/weak_ptr.hpp

    r09e02ee rde00da5  
    192192            shared_ptr<T> lock() const noexcept
    193193            {
    194                 return shared_ptr{payload_->lock()};
     194                return shared_ptr{aux::payload_tag, payload_->lock()};
    195195            }
    196196
Note: See TracChangeset for help on using the changeset viewer.