On Wed, 16 Jul 2025, Tomasz Kaminski wrote: > > > On Tue, Jul 15, 2025 at 9:51 PM Patrick Palka <ppa...@redhat.com> wrote: > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > -- >8 -- > > 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, > > optional<Iterator> is still smaller than 2 * sizeof(Iterator), so the > constraints > could be updated to range::difference <= 2 * sizeof(Iterator) or <= > sizeof(non_propagating_cache). > > However, having a range::difference_t being larger than iterator, should be > unusual, as the iterator must be able to represent as many positions as the > difference > type. So except for cases like repeat, they should be similar size. I do not > think > it is worth optimizing for that. > > I think it is easier for users if the caching rules are simplified, and does > not depend > on size. > > and it 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. > --- > > Given the above LGTM.
Thanks, Tomasz! Is this OK to push? > libstdc++-v3/include/std/ranges | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/libstdc++-v3/include/std/ranges > b/libstdc++-v3/include/std/ranges > index efe62969d657..2970b2cbe00b 100644 > --- a/libstdc++-v3/include/std/ranges > +++ b/libstdc++-v3/include/std/ranges > @@ -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: > -- > 2.50.1.271.gd30e120486 > > >