Combining infinite ranges
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Jun 2 18:21:49 PDT 2010
On 06/02/2010 08:04 PM, bearophile wrote:
> Andrei Alexandrescu:
>> No need to write enumerate() - it's zip(iota(0, size_t.max), r).
>
> What does it happen if someone gives you the sequence produced by:
> zip(r, iota(0, size_t.max))
> ?
> You have can require an adaptor because it's not the standard convention.
> While enumerate() always gives you indexes at the first place. And the index/item fields have a standard name that you remember in your code.
>
> Finding the minimal number of pieces to do something is useful, but sometimes if an operation is common enough it can be useful to give it a new name. It's called chunking.
>
> Inside an expression that can contain other stuff do you prefer to use:
> zip(iota(0, size_t.max), items)
> or
> enumerate(items)
> ?
> The second makes the expression shorter and more readable in its purpose.
>
> Bye,
> bearophile
My point was that there's no need to sit down and implement
functionality. Just write
auto enumerate(R)(R r) if (isInputRange!R)
{
return zip(iota(0, size_t.max), r);
}
Andrei
More information about the Digitalmars-d
mailing list