commit 8ca18880b4c6995fbccfb661eb652ebe9cd7f75f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Apr 18 16:58:13 2016 +0100
Define std::thread::id comparison operators at namespace-scope
@@ -88,22 +88,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend class hash<thread::id>;
friend bool
- operator==(thread::id __x, thread::id __y) noexcept
- {
- // pthread_equal is undefined if either thread ID is not valid, so we
- // can't safely use __gthread_equal on default-constructed values (nor
- // the non-zero value returned by this_thread::get_id() for
- // single-threaded programs using GNU libc). Assume EqualityComparable.
- return __x._M_thread == __y._M_thread;
- }
+ operator==(thread::id __x, thread::id __y) noexcept;
friend bool
- operator<(thread::id __x, thread::id __y) noexcept
- {
- // Pthreads doesn't define any way to do this, so we just have to
- // assume native_handle_type is LessThanComparable.
- return __x._M_thread < __y._M_thread;
- }
+ operator<(thread::id __x, thread::id __y) noexcept;
template<class _CharT, class _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -231,10 +219,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ __x.swap(__y); }
inline bool
+ operator==(thread::id __x, thread::id __y) noexcept
+ {
+ // pthread_equal is undefined if either thread ID is not valid, so we
+ // can't safely use __gthread_equal on default-constructed values (nor
+ // the non-zero value returned by this_thread::get_id() for
+ // single-threaded programs using GNU libc). Assume EqualityComparable.
+ return __x._M_thread == __y._M_thread;
+ }
+
+ inline bool
operator!=(thread::id __x, thread::id __y) noexcept
{ return !(__x == __y); }
inline bool
+ operator<(thread::id __x, thread::id __y) noexcept
+ {
+ // Pthreads doesn't define any way to do this, so we just have to
+ // assume native_handle_type is LessThanComparable.
+ return __x._M_thread < __y._M_thread;
+ }
+
+ inline bool
operator<=(thread::id __x, thread::id __y) noexcept
{ return !(__y < __x); }
new file mode 100644
@@ -0,0 +1,24 @@
+// Copyright (C) 2016 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <thread>
+
+bool (*lt)(std::thread::id, std::thread::id) = &std::operator<;
+bool (*eq)(std::thread::id, std::thread::id) = &std::operator==;