[PATCH] libstdc++: Implement P3060R3: Add std::views::indices(n)

Yuao Ma addr2line@gmail.com
Wed Oct 15 15:23:16 GMT 2025


Hi Jonathan,

Thanks for the information about the standard wording. Regarding this
patch, I'm wondering does it need any further refinement?

Yuao

On Wed, Oct 15, 2025 at 12:32 AM Yuao Ma <addr2line@gmail.com> wrote:
>
> On Wed, Oct 15, 2025 at 12:21 AM Jonathan Wakely <jwakely@redhat.com> wrote:
> >
> > On Tue, 14 Oct 2025 at 17:08, Yuao Ma <addr2line@gmail.com> wrote:
> > >
> > > Hi Hewill and Jonathan,
> > >
> > > On Tue, Oct 14, 2025 at 11:39 PM Hewill Kang <hewillk@gmail.com> wrote:
> > > >
> > > > 1. The prefix ranges:: in ranges::__detail::__is_integer_like can be removed.
> > >
> > > It can't. views has its own __detail namespace.
> > >
> > > > 2. Parameters should not be passed by reference; otherwise, const int i = 0; std::views::indices(i); will fail because const int& does not satisfy __is_integer_like.
> > >
> > > Yes I figure that out with the new testcase. Done.
> > >
> > > > 3. operator() can be static.
> > >
> > > I think I'll stick to the style of the existing functions.
> >
> > static operator() is a C++23 feature, so wasn't an option for the
> > original C++20 views.
> >
> > I'm not sure it makes much difference on the ABI used for most of our
> > supported targets, and it should be optimized away anyway. In fact, we
> > could add [[__gnu__::__always_inline__]] to the operator() here, since
> > it's incredibly simple.
> >
> >
> > > The testcase got updated, testing against different type and size. But
> > > ranges::__detail::max_{size, diff}_type not working here:
> >
> > Ah yes, that's a problem. If you create
> > views::indices(ranges::distance(views::iota(0ULL, 1ULL))) then you
> > need to create an iota_view of the difference type of iota(0ULL,
> > 1ULL), but that can't be represented. You would need an integer-like
> > type wider than our widest integer-like type.
> >
> > That might be a defect in the wording for views::indices, but that's
> > not your concern. There's no need to test it with that type then.
> >
>
> The updated patch is rfr now. Testcase updated with noexcept check.
>
> Yuao


More information about the Libstdc++ mailing list