Commit 7f359d19 by Daniel Kruegler Committed by Jonathan Wakely

Implement LWG 2686, std::hash<error_condition>, for C++17

2017-03-23  Daniel Kruegler  <daniel.kruegler@gmail.com>

	Implement LWG 2686, Why is std::hash specialized for error_code,
	but not error_condition?
	* include/std/system_error (hash<error_condition>): Define for C++17.
	* testsuite/20_util/hash/operators/size_t.cc (hash<error_condition>):
	Instantiate test for error_condition.
	* testsuite/20_util/hash/requirements/explicit_instantiation.cc
	(hash<error_condition>): Instantiate hash<error_condition>.

From-SVN: r246424
parent 288695f7
2017-03-23 Daniel Kruegler <daniel.kruegler@gmail.com> 2017-03-23 Daniel Kruegler <daniel.kruegler@gmail.com>
Implement LWG 2686, Why is std::hash specialized for error_code,
but not error_condition?
* include/std/system_error (hash<error_condition>): Define for C++17.
* testsuite/20_util/hash/operators/size_t.cc (hash<error_condition>):
Instantiate test for error_condition.
* testsuite/20_util/hash/requirements/explicit_instantiation.cc
(hash<error_condition>): Instantiate hash<error_condition>.
* include/bits/c++config (_GLIBCXX17_INLINE): Define. * include/bits/c++config (_GLIBCXX17_INLINE): Define.
* include/bits/regex_constants.h (All std::regex_constants constants): * include/bits/regex_constants.h (All std::regex_constants constants):
Add _GLIBCXX17_INLINE as per P0607R0. Add _GLIBCXX17_INLINE as per P0607R0.
......
...@@ -373,14 +373,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -373,14 +373,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
} // namespace } // namespace
#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
#include <bits/functional_hash.h> #include <bits/functional_hash.h>
namespace std _GLIBCXX_VISIBILITY(default) namespace std _GLIBCXX_VISIBILITY(default)
{ {
_GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
// DR 1182. // DR 1182.
/// std::hash specialization for error_code. /// std::hash specialization for error_code.
template<> template<>
...@@ -394,12 +393,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -394,12 +393,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp); return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
} }
}; };
#endif // _GLIBCXX_COMPATIBILITY_CXX0X
#if __cplusplus > 201402L
// DR 2686.
/// std::hash specialization for error_condition.
template<>
struct hash<error_condition>
: public __hash_base<size_t, error_condition>
{
size_t
operator()(const error_condition& __e) const noexcept
{
const size_t __tmp = std::_Hash_impl::hash(__e.value());
return std::_Hash_impl::__hash_combine(__e.category(), __tmp);
}
};
#endif
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
} // namespace } // namespace
#endif // _GLIBCXX_COMPATIBILITY_CXX0X
#endif // C++11 #endif // C++11
#endif // _GLIBCXX_SYSTEM_ERROR #endif // _GLIBCXX_SYSTEM_ERROR
...@@ -43,6 +43,9 @@ template<typename T> ...@@ -43,6 +43,9 @@ template<typename T>
void test01() void test01()
{ {
do_test<std::error_code>(); do_test<std::error_code>();
#if __cplusplus > 201402L
do_test<std::error_condition>();
#endif
} }
int main() int main()
......
...@@ -40,6 +40,9 @@ template class std::hash<long double>; ...@@ -40,6 +40,9 @@ template class std::hash<long double>;
template class std::hash<void*>; template class std::hash<void*>;
template class std::hash<std::string>; template class std::hash<std::string>;
template class std::hash<std::error_code>; template class std::hash<std::error_code>;
#if __cplusplus > 201402L
template class std::hash<std::error_condition>;
#endif
#ifdef _GLIBCXX_USE_WCHAR_T #ifdef _GLIBCXX_USE_WCHAR_T
template class std::hash<wchar_t>; template class std::hash<wchar_t>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment