c++-coroutines - Use spaceship in coroutines header.

The (n4835) CD removes the regular comparisons in the coroutine header and
replaces them with the three-way comparison.  We don't want to do that
unconditionally, since we support using coroutines with c++14 etc.

This makes the use of the spaceship operator conditional on the same
cases that the <compare> header uses.

2019-11-12  Iain Sandoe  <iain@sandoe.co.uk>

	libstdc++-v3/
	* include/experimental/coroutine: Adjust to use spaceship operator
	when it's available.

From-SVN: r278097
This commit is contained in:
Iain Sandoe
2019-11-12 16:00:49 +00:00
committed by Iain Sandoe
parent f35c258592
commit fcb4545280
2 changed files with 21 additions and 7 deletions

View File

@@ -1,3 +1,9 @@
2019-11-12 Iain Sandoe <iain@sandoe.co.uk>
libstdc++-v3/
* include/experimental/coroutine: Adjust to use spaceship operator
when it's available.
2019-11-12 Iain Sandoe <iain@sandoe.co.uk>
gcc/c-family/

View File

@@ -38,7 +38,14 @@
#if __cplusplus >= 201402L
#include <bits/c++config.h>
#include <bits/stl_function.h>
#if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L
# include <compare>
# define THE_SPACESHIP_HAS_LANDED 1
#else
# include <bits/stl_function.h>
# define THE_SPACESHIP_HAS_LANDED 0
#endif
namespace std _GLIBCXX_VISIBILITY (default)
{
@@ -105,18 +112,18 @@ namespace std _GLIBCXX_VISIBILITY (default)
}
};
// 4830 17.12.3.6 Comparison operators
// [coroutine.handle.compare]
// 4835 17.12.3.6
constexpr bool operator== (coroutine_handle<> __a,
coroutine_handle<> __b) noexcept
{
return __a.address () == __b.address ();
}
// We do not have spaceship yet, so this is...
// TODO:
// constexpr strong_ordering
// operator<=> (coroutine_handle<> __a, coroutine_handle<> __b) noexcept;
#if THE_SPACESHIP_HAS_LANDED
constexpr strong_ordering
operator<=> (coroutine_handle<> __a, coroutine_handle<> __b) noexcept;
#else
constexpr bool operator!= (coroutine_handle<> __a,
coroutine_handle<> __b) noexcept
{
@@ -146,6 +153,7 @@ namespace std _GLIBCXX_VISIBILITY (default)
{
return !(__a < __b);
}
#endif
template <class _Promise> struct coroutine_handle : coroutine_handle<>
{