* [PATCH] Deprecate nested types in std::hash
@ 2017-09-20 16:34 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2017-09-20 16:34 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1425 bytes --]
C++17 deprecates the argument_type and result_type members of
std::hash specializations. This adds the deprecated attribute to them.
C++17 also deprecates those nested typedefs (and weak result types) in
owner_less, plus, minus, function, reference_wrapper, bind,
{multi,}map::value_compare etc. but we can do that later. I wanted to
make this change now for the new hash<variant<T...>> and
hash<optional<T>> specializations that are new in C++17.
I'm also adding partial specializations for __is_fast_hash for those
new hash specializations, so that unordered containers of
optional<string> or variant<..., string, ...> will cache the hash
code.
* include/bits/c++config (_GLIBCXX17_DEPRECATED): Define.
* include/bits/functional_hash.h (__hash_base::result_type)
(__hash_base::argument_type): Add _GLIBCXX17_DEPRECATED.
* include/std/optional (hash<optional<T>>::result_type)
(hash<optional<T>>::argument_type): Add deprecated attribute.
(__is_fast_hash<hash<optional<T>>>): Add partial specialization.
* include/std/variant (hash<variant<Types...>>::result_type)
(hash<variant<Types...>>::argument_type): Add deprecated attribute.
(__is_fast_hash<hash<variant<Types...>>>): Add partial specialization.
Tested powerpc64le, committed to trunk.
I don't think this is suitable for backporting to gcc-7-branch. The
__is_fast_hash parts would cause incompatibilities between 7.2 and 7.3
for unordered containers.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 4148 bytes --]
commit 5ecfc92eb86d8e6a90e1168fe6b4b2ab8cd0f8e4
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Sep 20 14:33:42 2017 +0100
Deprecate nested types in std::hash
* include/bits/c++config (_GLIBCXX17_DEPRECATED): Define.
* include/bits/functional_hash.h (__hash_base::result_type)
(__hash_base::argument_type): Add _GLIBCXX17_DEPRECATED.
* include/std/optional (hash<optional<T>>::result_type)
(hash<optional<T>>::argument_type): Add deprecated attribute.
(__is_fast_hash<hash<optional<T>>>): Add partial specialization.
* include/std/variant (hash<variant<Types...>>::result_type)
(hash<variant<Types...>>::argument_type): Add deprecated attribute.
(__is_fast_hash<hash<variant<Types...>>>): Add partial specialization.
diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index d5d1d24ee1a..21e3fbb2741 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -77,6 +77,7 @@
// Macros for deprecated attributes.
// _GLIBCXX_USE_DEPRECATED
// _GLIBCXX_DEPRECATED
+// _GLIBCXX17_DEPRECATED
#ifndef _GLIBCXX_USE_DEPRECATED
# define _GLIBCXX_USE_DEPRECATED 1
#endif
@@ -87,6 +88,12 @@
# define _GLIBCXX_DEPRECATED
#endif
+#if defined(__DEPRECATED) && (__cplusplus >= 201703L)
+# define _GLIBCXX17_DEPRECATED [[__deprecated__]]
+#else
+# define _GLIBCXX17_DEPRECATED
+#endif
+
// Macros for ABI tag attributes.
#ifndef _GLIBCXX_ABI_TAG_CXX11
# define _GLIBCXX_ABI_TAG_CXX11 __attribute ((__abi_tag__ ("cxx11")))
diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h
index 38be1724d3f..c0936843ac0 100644
--- a/libstdc++-v3/include/bits/functional_hash.h
+++ b/libstdc++-v3/include/bits/functional_hash.h
@@ -49,8 +49,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Result, typename _Arg>
struct __hash_base
{
- typedef _Result result_type;
- typedef _Arg argument_type;
+ typedef _Result result_type _GLIBCXX17_DEPRECATED;
+ typedef _Arg argument_type _GLIBCXX17_DEPRECATED;
};
/// Primary class template hash.
diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index 2df9b5443ef..e017eedbde7 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -1028,10 +1028,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: private __poison_hash<remove_const_t<_Tp>>,
public __optional_hash_call_base<_Tp>
{
- using result_type = size_t;
- using argument_type = optional<_Tp>;
+ using result_type [[__deprecated__]] = size_t;
+ using argument_type [[__deprecated__]] = optional<_Tp>;
};
+ template<typename _Tp>
+ struct __is_fast_hash<hash<optional<_Tp>>> : __is_fast_hash<hash<_Tp>>
+ { };
+
/// @}
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index ee2571b7857..8f574f63924 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1420,15 +1420,15 @@ namespace __variant
variant<_Types...>, std::index_sequence_for<_Types...>>,
public __variant_hash_call_base<_Types...>
{
- using result_type = size_t;
- using argument_type = variant<_Types...>;
+ using result_type [[__deprecated__]] = size_t;
+ using argument_type [[__deprecated__]] = variant<_Types...>;
};
template<>
struct hash<monostate>
{
- using result_type = size_t;
- using argument_type = monostate;
+ using result_type [[__deprecated__]] = size_t;
+ using argument_type [[__deprecated__]] = monostate;
size_t
operator()(const monostate& __t) const noexcept
@@ -1438,6 +1438,11 @@ namespace __variant
}
};
+ template<typename... _Types>
+ struct __is_fast_hash<hash<variant<_Types...>>>
+ : bool_constant<(__is_fast_hash<_Types>::value && ...)>
+ { };
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-09-20 16:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-20 16:34 [PATCH] Deprecate nested types in std::hash Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).