diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-06-11 16:20:24 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-06-11 16:20:24 +0000 |
commit | f4f18004789eb925cb8ed8e2b282bcac3ddc40eb (patch) | |
tree | aa7302db648ad8852e5444d9a24bd8ad8a8bbbf3 /libstdc++-v3 | |
parent | 1a8fcc169cbceb7238811ffdaae34573c8bed004 (diff) | |
download | gcc-f4f18004789eb925cb8ed8e2b282bcac3ddc40eb.tar.gz |
2010-06-11 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (hash<shared_ptr>): Add.
* include/bits/shared_ptr_base.h (hash<__shared_ptr>): Likewise.
* include/bits/unique_ptr.h (hash<unique_ptr>): Likewise.
* testsuite/20_util/shared_ptr/hash/1.cc: New.
* testsuite/20_util/unique_ptr/hash/1.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160621 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr.h | 10 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr_base.h | 10 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/unique_ptr.h | 15 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/shared_ptr/hash/1.cc | 48 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc | 48 |
6 files changed, 138 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e2a1c9ae4c1..96dd53a6a47 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2010-06-11 Paolo Carlini <paolo.carlini@oracle.com> + + * include/bits/shared_ptr.h (hash<shared_ptr>): Add. + * include/bits/shared_ptr_base.h (hash<__shared_ptr>): Likewise. + * include/bits/unique_ptr.h (hash<unique_ptr>): Likewise. + * testsuite/20_util/shared_ptr/hash/1.cc: New. + * testsuite/20_util/unique_ptr/hash/1.cc: Likewise. + 2010-06-11 Jonathan Wakely <jwakely.gcc@gmail.com> * doc/xml/manual/appendix_contributing.xml: Indent code examples diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index f01630e5347..4f87dd459cf 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -514,6 +514,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) std::forward<_Args>(__args)...); } + /// std::hash specialization for shared_ptr. + template<typename _Tp> + struct hash<shared_ptr<_Tp>> + : public std::unary_function<shared_ptr<_Tp>, size_t> + { + size_t + operator()(const shared_ptr<_Tp>& __s) const + { return std::hash<_Tp*>()(__s.get()); } + }; + // @} group pointer_abstractions _GLIBCXX_END_NAMESPACE diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index d4c8c8fb824..0a69d2b2411 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1164,6 +1164,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) std::forward<_Args>(__args)...); } + /// std::hash specialization for __shared_ptr. + template<typename _Tp, _Lock_policy _Lp> + struct hash<__shared_ptr<_Tp, _Lp>> + : public std::unary_function<__shared_ptr<_Tp, _Lp>, size_t> + { + size_t + operator()(const __shared_ptr<_Tp, _Lp>& __s) const + { return std::hash<_Tp*>()(__s.get()); } + }; + _GLIBCXX_END_NAMESPACE #endif // _SHARED_PTR_BASE_H diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 77d3f607dfd..ac62ff7f304 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -233,7 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // [unique.ptr.runtime] // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 740 - omit specialization for array objects with a compile time length - template<typename _Tp, typename _Tp_Deleter> + template<typename _Tp, typename _Tp_Deleter> class unique_ptr<_Tp[], _Tp_Deleter> { typedef std::tuple<_Tp*, _Tp_Deleter> __tuple_type; @@ -444,6 +444,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std) const unique_ptr<_Up, _Up_Deleter>& __y) { return !(__x.get() < __y.get()); } + /// std::hash specialization for unique_ptr. + template<typename _Tp, typename _Tp_Deleter> + struct hash<unique_ptr<_Tp, _Tp_Deleter>> + : public std::unary_function<unique_ptr<_Tp, _Tp_Deleter>, size_t> + { + size_t + operator()(const unique_ptr<_Tp, _Tp_Deleter>& __u) const + { + typedef unique_ptr<_Tp, _Tp_Deleter> _UP; + return std::hash<typename _UP::pointer>()(__u.get()); + } + }; + // @} group pointer_abstractions _GLIBCXX_END_NAMESPACE diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/hash/1.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/hash/1.cc new file mode 100644 index 00000000000..93f4739d782 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/hash/1.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-11 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <memory> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + struct T { }; + + std::shared_ptr<T> s0(new T); + std::hash<std::shared_ptr<T>> hs0; + std::hash<T*> hp0; + + VERIFY( hs0(s0) == hp0(s0.get()) ); + + std::__shared_ptr<T> s1(new T); + std::hash<std::__shared_ptr<T>> hs1; + std::hash<T*> hp1; + + VERIFY( hs1(s1) == hp1(s1.get()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc new file mode 100644 index 00000000000..53ece26ecff --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-11 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <memory> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + struct T { }; + + std::unique_ptr<T> u0(new T); + std::hash<std::unique_ptr<T>> hu0; + std::hash<typename std::unique_ptr<T>::pointer> hp0; + + VERIFY( hu0(u0) == hp0(u0.get()) ); + + std::unique_ptr<T[]> u1(new T[10]); + std::hash<std::unique_ptr<T[]>> hu1; + std::hash<typename std::unique_ptr<T[]>::pointer> hp1; + + VERIFY( hu1(u1) == hp1(u1.get()) ); +} + +int main() +{ + test01(); + return 0; +} |