Last element of a forward range

Steven Schveighoffer schveiguy at yahoo.com
Fri Apr 11 20:41:47 PDT 2014


On Fri, 11 Apr 2014 21:05:26 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> If I have a range like this, how do you find its last item using Phobos?
>
> A simple way is to use seq.array.back, but this wastes memory. Another  
> simple way is to use a foreach loop keeping the last seen. But do you  
> know if there is a function to do in Phobos? And if such function is not  
> present (walkBack? backWalk?) is it a good idea to add it to Phobos?

Interesting problem. Given that it is a forward range, a zip between it  
and a saved copy that is advanced by one may work.

-Steve


More information about the Digitalmars-d-learn mailing list