<br><div class="gmail_quote">On Wed, Jun 2, 2010 at 21:41, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org">SeeWebsiteForEmail@erdani.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On 06/02/2010 02:29 PM, Philippe Sigaud wrote:<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
<br>
<br>
On Wed, Jun 2, 2010 at 19:57, bearophile <<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a><br></div><div><div></div><div class="h5">
<mailto:<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a>>> wrote:<br>
<br>
Philippe Sigaud:<br>
> What, do you also need the no-arg version of iota?<br>
><br>
> :-p<br>
<br>
I'd like a generator (range) similar to the Python itertools.count,<br>
that yields numbers starting from the given number (defaulting to<br>
zero) and just goes on and on. You can use it in many situations:<br>
<a href="http://docs.python.org/library/itertools.html#itertools.count" target="_blank">http://docs.python.org/library/itertools.html#itertools.count</a><br>
<br>
<br></div></div><div class="im">
Yes, it's handy. It's one of the first range I made, a year ago.<br>
</div></blockquote>
<br>
iota(n, n.max) is close. Well, it's not infinite, but cycle(iota(n, n.max)) is. Probably a version using BigInt would be most sensible.<font color="#888888"><br></font></blockquote><div><br><br></div><div><br>As it's mostly used to enumerate/index ranges or generate some simple numbers, iota(n,n.max) is largely good enough, except, as you said it's not infinite. I never used iota much, it regularly crashed on me in the beginning. I can't remember why.<br>
<br>I don't know if your suggestion of BigInt is a joke or not, but the truth is, I have a version using any numerical type, I called it numberz. numbers is the standard version, numberz!T the templated. It uses T for indexing also (it's a random-access range), which allowed me to do<br>
<br>auto r = numberz(BigInt("1000000000"), BigInt("10000000000"));<br>auto n = r[BigInt("3000000000")];<br><br><br>Hmm, this doesn't work:<br>auto i = iota(BigInt("0"),BigInt("10"), BigInt("1"));<br>
<br>But honestly, I just used it to learn ranges and D, and never had a real use for it. It's just the kind of things that's useful to try, to break out of some preconceptions (using a size_t to index..., 1u as a step).<br>
As you said, it already takes loooots of iterations to exhaust a long.<br><br><br> Philippe<br></div></div>