Changeset 999cb48 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:
edd2e61
Parents:
aedae28
git-author:
Dzejrou <dzejrou@…> (2018-05-10 00:36:39)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
Message:

cpp: added hash support for smart pointers

Location:
uspace/lib/cpp/include
Files:
2 edited

Legend:

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

    raedae28 r999cb48  
    3131
    3232#include <internal/aux.hpp>
     33#include <internal/functional/hash.hpp>
    3334#include <internal/memory/allocator_arg.hpp>
    3435#include <internal/memory/addressof.hpp>
     
    10981099        return !(nullptr < ptr);
    10991100    }
     1101
     1102    /**
     1103     * 20.8.2.7, smart pointer hash support:
     1104     */
     1105
     1106    template<class T, class D>
     1107    struct hash<unique_ptr<T, D>>
     1108    {
     1109        size_t operator()(const unique_ptr<T, D>& ptr) const noexcept
     1110        {
     1111            return hash<typename unique_ptr<T, D>::pointer>{}(ptr.get());
     1112        }
     1113
     1114        using argument_type = unique_ptr<T, D>;
     1115        using result_type   = size_t;
     1116    };
    11001117}
    11011118
  • uspace/lib/cpp/include/internal/memory/shared_ptr.hpp

    raedae28 r999cb48  
    3232#include <exception>
    3333#include <internal/functional/arithmetic_operations.hpp>
     34#include <internal/functional/hash.hpp>
    3435#include <internal/memory/allocator_arg.hpp>
    3536#include <internal/memory/shared_payload.hpp>
     
    605606        return os << ptr.get();
    606607    }
     608
     609    /**
     610     * 20.8.2.5, class template enable_shared_from_this:
     611     */
     612
     613    // TODO: implement
     614
     615    /**
     616     * 20.8.2.6, shared_ptr atomic access
     617     */
     618
     619    // TODO: implement
     620
     621    /**
     622     * 20.8.2.7, smart pointer hash support:
     623     */
     624
     625    template<class T>
     626    struct hash<shared_ptr<T>>
     627    {
     628        size_t operator()(const shared_ptr<T>& ptr) const noexcept
     629        {
     630            return hash<T*>{}(ptr.get());
     631        }
     632
     633        using argument_type = shared_ptr<T>;
     634        using result_type   = size_t;
     635    };
    607636}
    608637
Note: See TracChangeset for help on using the changeset viewer.