myrange.at(i) for myrange.dropExactly(i).front
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 27 21:20:14 PDT 2014
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
More information about the Digitalmars-d-learn
mailing list