C++ Logo

std-proposals

Advanced search

Re: int arr[] = {1..10}; (or for containers)

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 8 Aug 2021 14:44:14 -0400
On Sun, Aug 8, 2021 at 1:10 PM sreeraj c via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Instead of using std::iota or loops, when we have compile time
> constant values it would be easy to write like this.
>
>
> Thanks
> Sreeraj
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

With constexpr ranges, and P1858, we can achieve the same effect
without further language changes:

int arr[] = {[:]std::ranges::iota(1, 10)...};

There's no need to make such a narrow language change that only
benefits one small use case when we can just permit something like
this to work.

That being said, I'm not sure how useful this is in general. Do people
really need this so often that we need dedicated syntax for it?

Received on 2021-08-08 13:44:29