public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Implement LWG 2686, hash<error_condition>
@ 2017-03-12 12:16 Daniel Krügler
  2017-03-21 21:26 ` Daniel Krügler
  2017-03-23 17:50 ` Jonathan Wakely
  0 siblings, 2 replies; 12+ messages in thread
From: Daniel Krügler @ 2017-03-12 12:16 UTC (permalink / raw)
  To: libstdc++, gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 478 bytes --]

The following is an *untested* patch suggestion, please verify.

Notes: My interpretation is that hash<error_condition> should be
defined outside of the _GLIBCXX_COMPATIBILITY_CXX0X block, please
double-check that course of action.

I noticed that the preexisting hash<error_code> did directly refer to
the private members of error_code albeit those have public access
functions. For consistency I mimicked that existing style when
implementing hash<error_condition>.

- Daniel

[-- Attachment #2: lwg2686.patch --]
[-- Type: application/octet-stream, Size: 2334 bytes --]

Index: include/std/system_error
===================================================================
--- include/std/system_error	(revision 246076)
+++ include/std/system_error	(working copy)
@@ -268,6 +268,8 @@
 
     // DR 804.
   private:
+    friend class hash<error_condition>;
+
     int 			_M_value;
     const error_category* 	_M_cat;
   };
@@ -372,8 +374,6 @@
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
-#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
-
 #include <bits/functional_hash.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -380,6 +380,7 @@
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
   // DR 1182.
   /// std::hash specialization for error_code.
   template<>
@@ -393,12 +394,25 @@
 	return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
       }
     };
+#endif // _GLIBCXX_COMPATIBILITY_CXX0X
 
+  // 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._M_value);
+	return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
+      }
+    };
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
-#endif // _GLIBCXX_COMPATIBILITY_CXX0X
-
 #endif // C++11
 
 #endif // _GLIBCXX_SYSTEM_ERROR
Index: testsuite/20_util/hash/operators/size_t.cc
===================================================================
--- testsuite/20_util/hash/operators/size_t.cc	(revision 246076)
+++ testsuite/20_util/hash/operators/size_t.cc	(working copy)
@@ -43,6 +43,7 @@
 void test01()
 {
   do_test<std::error_code>();
+  do_test<std::error_condition>();
 }
 
 int main()
Index: testsuite/20_util/hash/requirements/explicit_instantiation.cc
===================================================================
--- testsuite/20_util/hash/requirements/explicit_instantiation.cc	(revision 246076)
+++ testsuite/20_util/hash/requirements/explicit_instantiation.cc	(working copy)
@@ -40,6 +40,7 @@
 template class std::hash<void*>;
 template class std::hash<std::string>;
 template class std::hash<std::error_code>;
+template class std::hash<std::error_condition>;
 
 #ifdef _GLIBCXX_USE_WCHAR_T
 template class std::hash<wchar_t>;

[-- Attachment #3: ChangeLog_lwg2686.patch --]
[-- Type: application/octet-stream, Size: 785 bytes --]

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 246076)
+++ ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2017-03-12  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.
+    * 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>.
+    
 2017-03-12  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
 	Implement LWG 2934, optional<const T> doesn't compare with T.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-05-29 10:55 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-12 12:16 [PATCH] Implement LWG 2686, hash<error_condition> Daniel Krügler
2017-03-21 21:26 ` Daniel Krügler
2017-03-23 17:50 ` Jonathan Wakely
     [not found]   ` <20190503224255.GI2599@redhat.com>
2019-05-04 14:36     ` Jonathan Wakely
2019-05-07  9:06       ` Christophe Lyon
2019-05-07  9:37         ` Jonathan Wakely
2019-05-07 10:07           ` Jonathan Wakely
2019-05-07 12:22             ` Christophe Lyon
2019-05-09 14:43               ` Szabolcs Nagy
2019-05-09 15:17                 ` Jonathan Wakely
2019-05-29 11:09                   ` Szabolcs Nagy
2019-05-07 15:27       ` 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).