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>
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/regex_constants.h (All std::regex_constants constants):
Add _GLIBCXX17_INLINE as per P0607R0.
......
......@@ -373,14 +373,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
#include <bits/functional_hash.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
// DR 1182.
/// std::hash specialization for error_code.
template<>
......@@ -394,12 +393,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
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
} // namespace
#endif // _GLIBCXX_COMPATIBILITY_CXX0X
#endif // C++11
#endif // _GLIBCXX_SYSTEM_ERROR
......@@ -43,6 +43,9 @@ template<typename T>
void test01()
{
do_test<std::error_code>();
#if __cplusplus > 201402L
do_test<std::error_condition>();
#endif
}
int main()
......
......@@ -40,6 +40,9 @@ template class std::hash<long double>;
template class std::hash<void*>;
template class std::hash<std::string>;
template class std::hash<std::error_code>;
#if __cplusplus > 201402L
template class std::hash<std::error_condition>;
#endif
#ifdef _GLIBCXX_USE_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