]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++/ranges: Prefer using offset-based _CachedPosition
authorPatrick Palka <ppalka@redhat.com>
Tue, 26 Aug 2025 19:45:57 +0000 (15:45 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 26 Aug 2025 19:45:57 +0000 (15:45 -0400)
The offset-based partial specialization of _CachedPosition for
random-access iterators is currently only selected if the offset type is
smaller than the iterator type.  Before r12-1018-g46ed811bcb4b86 this
made sense since the main partial specialization only stored the
iterator (incorrectly).  After that bugfix, the main partial
specialization now effectively stores a std::optional<iter> so the
size constraint is inaccurate.  And this main partial specialization
must invalidate itself upon copy/move unlike the offset-based partial
specialization.  So I think we should just always prefer the
offset-based _CachedPosition for a random-access iterator, even if the
offset type happens to be larger than the iterator type.

libstdc++-v3/ChangeLog:

* include/std/ranges (__detail::_CachedPosition): Remove
additional size constraint on the offset-based partial
specialization.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/std/ranges

index efe62969d657d141686962d1aad26587962fc8b4..2970b2cbe00b247274f2a5d516ab08105c903fb6 100644 (file)
@@ -1585,8 +1585,6 @@ namespace views::__adaptor
       };
 
     template<random_access_range _Range>
-      requires (sizeof(range_difference_t<_Range>)
-               <= sizeof(iterator_t<_Range>))
       struct _CachedPosition<_Range>
       {
       private: