libstdc++: Add missing constraint to operator+ for std::move_iterator

This constraint was added by the One Ranges proposal (P0896R4) and
then fixed by LWG 3293, but it was missing from libstdc++.

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (operator+): Add constraint to
	move_iterator operator.
	* testsuite/24_iterators/move_iterator/rel_ops_c++20.cc:
This commit is contained in:
Jonathan Wakely 2024-11-14 10:50:34 +00:00 committed by Jonathan Wakely
parent dec2158b2c
commit f91e34644e
No known key found for this signature in database
2 changed files with 16 additions and 0 deletions

View File

@ -1731,6 +1731,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline _GLIBCXX17_CONSTEXPR bool
operator==(const move_iterator<_Iterator>& __x,
const move_iterator<_Iterator>& __y)
// N.B. No contraints, x.base() == y.base() is always well-formed.
{ return __x.base() == __y.base(); }
#ifdef __cpp_lib_three_way_comparison
@ -1791,6 +1792,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
operator+(typename move_iterator<_Iterator>::difference_type __n,
const move_iterator<_Iterator>& __x)
#ifdef __glibcxx_concepts
requires requires { { __x.base() + __n } -> same_as<_Iterator>; }
#endif
{ return __x + __n; }
template<typename _Iterator>

View File

@ -18,6 +18,7 @@
// { dg-do compile { target c++20 } }
#include <iterator>
#include <testsuite_iterators.h>
template<int>
struct Iter
@ -141,3 +142,14 @@ static_assert( cend > beg );
static_assert( beg <= cend );
static_assert( cend >= beg );
static_assert( std::is_lt(beg <=> cend) );
template<typename I>
concept has_plus = requires(std::iter_difference_t<I> n, I i) {
{ n + i } -> std::same_as<I>;
};
using namespace __gnu_test;
using MBI = std::move_iterator<bidirectional_iterator_wrapper<int>>;
static_assert( ! has_plus<MBI> );
using MRI = std::move_iterator<random_access_iterator_wrapper<int>>;
static_assert( has_plus<MRI> );