diff --git a/stl/inc/xutility b/stl/inc/xutility index 361e55718ce..5c470ceec76 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -2576,16 +2576,19 @@ namespace ranges { public: using _Not_quite_object::_Not_quite_object; - template > _Se> - _NODISCARD constexpr iter_difference_t> operator()(_It&& _Raw_first, _Se _Last) const - noexcept(_Nothrow_dist<_It, _Se>) /* strengthened */ { - if constexpr (sized_sentinel_for<_Se, decay_t<_It>>) { - return _Last - static_cast&>(_Raw_first); // Per LWG-3664 - } else { - auto _First = _STD forward<_It>(_Raw_first); - _Adl_verify_range(_First, _Last); - return _Distance_unchecked(_Get_unwrapped(_STD move(_First)), _Get_unwrapped(_STD move(_Last))); - } + template _Se> + requires(!sized_sentinel_for<_Se, _It>) + _NODISCARD constexpr iter_difference_t<_It> operator()(_It _First, _Se _Last) const + noexcept(noexcept(_Distance_unchecked(_Get_unwrapped(_STD move(_First)), + _Get_unwrapped(_STD move(_Last))))) /* strengthened */ { // Per LWG-3664 + _Adl_verify_range(_First, _Last); + return _Distance_unchecked(_Get_unwrapped(_STD move(_First)), _Get_unwrapped(_STD move(_Last))); + } + + template > _Se> + _NODISCARD constexpr iter_difference_t> operator()(_It&& _First, const _Se _Last) const + noexcept(noexcept(_Last - static_cast&>(_First))) /* strengthened */ { // Per LWG-3664 + return _Last - static_cast&>(_First); } template @@ -2599,13 +2602,6 @@ namespace ranges { } private: - template - static constexpr bool _Nothrow_dist = false; - - template > _Se> - static constexpr bool _Nothrow_dist<_It, _Se> = noexcept( - _STD declval<_Se&>() - _STD declval&>()); - template _NODISCARD static constexpr iter_difference_t<_It> _Distance_unchecked(_It _First, const _Se _Last) noexcept( noexcept(++_First != _Last)) { diff --git a/tests/std/tests/P0896R4_ranges_iterator_machinery/test.cpp b/tests/std/tests/P0896R4_ranges_iterator_machinery/test.cpp index 0a9e743930b..563a0229e36 100644 --- a/tests/std/tests/P0896R4_ranges_iterator_machinery/test.cpp +++ b/tests/std/tests/P0896R4_ranges_iterator_machinery/test.cpp @@ -2959,7 +2959,7 @@ namespace iter_ops { trace t{}; I first{t}; same_as> auto const result = distance(move(first), default_sentinel); - STATIC_ASSERT(!noexcept(distance(move(first), default_sentinel))); // No conditional noexcept + STATIC_ASSERT(noexcept(distance(move(first), default_sentinel))); assert(result == sentinel_position); assert((t == trace{.compares_ = sentinel_position + 1, .increments_ = sentinel_position})); }