From 21aefc3a6135c6447b8b43ac3f2349bf568e2900 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 3 Jun 2010 16:42:57 +0000 Subject: [PATCH] [util.smartptr.hash] git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@105393 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/functional | 11 +----- include/memory | 36 +++++++++++++++++++ src/mutex.cpp | 2 +- .../hash_shared_ptr.pass.cpp | 1 + .../hash_unique_ptr.pass.cpp | 1 + .../tuple.creation/pack_arguments.pass.cpp | 21 +++++++++++ 6 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp create mode 100644 test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp create mode 100644 test/utilities/tuple/tuple.tuple/tuple.creation/pack_arguments.pass.cpp diff --git a/include/functional b/include/functional index 57112a25..e645a55e 100644 --- a/include/functional +++ b/include/functional @@ -1834,16 +1834,7 @@ struct hash } }; -template -struct hash<_Tp*> - : public unary_function<_Tp*, size_t> -{ - size_t operator()(_Tp* __v) const - { - const size_t* const __p = reinterpret_cast(&__v); - return *__p; - } -}; +// struct hash in _LIBCPP_END_NAMESPACE_STD diff --git a/include/memory b/include/memory index 10122c7a..8af5ed76 100644 --- a/include/memory +++ b/include/memory @@ -2463,6 +2463,31 @@ inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} +template struct hash; + +template +struct hash<_Tp*> + : public unary_function<_Tp*, size_t> +{ + size_t operator()(_Tp* __v) const + { + const size_t* const __p = reinterpret_cast(&__v); + return *__p; + } +}; + +template +struct hash > +{ + typedef unique_ptr<_Tp, _Dp> argument_type; + typedef size_t result_type; + result_type operator()(const argument_type& __ptr) const + { + typedef typename argument_type::pointer pointer; + return hash()(__ptr.get()); + } +}; + struct __destruct_n { private: @@ -3785,6 +3810,17 @@ public: template friend class shared_ptr; }; +template +struct hash > +{ + typedef shared_ptr<_Tp> argument_type; + typedef size_t result_type; + result_type operator()(const argument_type& __ptr) const + { + return hash<_Tp*>()(__ptr.get()); + } +}; + //enum class struct pointer_safety { diff --git a/src/mutex.cpp b/src/mutex.cpp index 7ea73496..1f8160d0 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -235,7 +235,7 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) pthread_mutex_lock(&mut); flag = 0ul; pthread_mutex_unlock(&mut); - pthread_cond_signal(&cv); + pthread_cond_broadcast(&cv); throw; } } diff --git a/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp b/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp new file mode 100644 index 00000000..9912d1b8 --- /dev/null +++ b/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp @@ -0,0 +1 @@ +//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // template // struct hash> // { // typedef shared_ptr argument_type; // typedef size_t result_type; // size_t operator()(const shared_ptr& p) const; // }; #include #include int main() { int* ptr = new int; std::shared_ptr p(ptr); std::hash > f; std::size_t h = f(p); assert(h == std::hash()(ptr)); } \ No newline at end of file diff --git a/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp b/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp new file mode 100644 index 00000000..0541e57a --- /dev/null +++ b/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp @@ -0,0 +1 @@ +//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // template // struct hash> // { // typedef unique_ptr argument_type; // typedef size_t result_type; // size_t operator()(const unique_ptr& p) const; // }; #include #include int main() { int* ptr = new int; std::unique_ptr p(ptr); std::hash > f; std::size_t h = f(p); assert(h == std::hash()(ptr)); } \ No newline at end of file diff --git a/test/utilities/tuple/tuple.tuple/tuple.creation/pack_arguments.pass.cpp b/test/utilities/tuple/tuple.tuple/tuple.creation/pack_arguments.pass.cpp new file mode 100644 index 00000000..6b7f1891 --- /dev/null +++ b/test/utilities/tuple/tuple.tuple/tuple.creation/pack_arguments.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// tuple pack_arguments(Types&&... t); + + +#include + +int main() +{ +#error pack_arguments not implemented +}