myrange.at(i) for myrange.dropExactly(i).front

Timothee Cour via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 29 21:28:33 PDT 2014


On Sun, Jul 27, 2014 at 9:20 PM, H. S. Teoh via Digitalmars-d-learn <
digitalmars-d-learn at puremagic.com> wrote:

> On Sun, Jul 27, 2014 at 07:42:17PM -0700, Timothee Cour via
> Digitalmars-d-learn wrote:
> > Just for clarification, I wanted 'myrange.at(i)' to be the same as
> > `myrange.dropExactly(i).front`
> > (so I don't assume it's a random access range).
> >
> > >> myrange.dropExactly(i).front makes it much more obvious what you're
> > doing and that it's inefficient. It might be necessary in some cases,
> > but we don't want to give the impression that it's cheap, which at()
> > would do.
> >
> > I think it's already clear that it's potentially O(n) [n=i] cost as
> > we're not using myrange[i]. But fine, call it atWalk/walkAt/whatever.
> > Point is it's a common enough operation.
> [...]
>
> You could just define your own function for it, right?
>
>         // or call it whatever you want
>         auto getNth(R)(R range, size_t index)
>                 if (isInputRange!R)
>         {
>                 return range.dropExactly(index).front;
>         }
>
>
> T
>
> --
> Making non-nullable pointers is just plugging one hole in a cheese grater.
> -- Walter Bright
>


Obviously I did that, but I thought it belonged in phobos. Anyway, closing
this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140729/03ca1be2/attachment.html>


More information about the Digitalmars-d-learn mailing list