www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - save() feature for iota

reply Salih Dincer <salihdb hotmail.com> writes:
Hi All,

Isn't there a save feature for `iota()`?

```d
import std.stdio;
import std.range;

void main()
{
   foreach(num; iota!char('a', 'f').chunks(3)/*
               "onetwosixfour".chunks(3)//*/
   ) {
		//auto n = num.save();
		num.writeln(": ", num.walkLength);
   }
} /* Prints:
: 3
: 2
*/
```
So is there a way to find out the length of an `iota()` range 
without consuming it?

SDB 79
Nov 02 2022
parent reply Paul Backus <snarwin gmail.com> writes:
On Thursday, 3 November 2022 at 06:26:22 UTC, Salih Dincer wrote:
 Hi All,

 Isn't there a save feature for `iota()`?
Looking at the source, it seems that only the numeric overloads of `iota` implement `save`. I think this is probably just an oversight, though, since I can't see any reason why `save` wouldn't work just as well for the generic version. I've submitted an enhancement request for this to the D bug tracker: https://issues.dlang.org/show_bug.cgi?id=23453
Nov 03 2022
next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 11/3/22 04:58, Paul Backus wrote:

 https://issues.dlang.org/show_bug.cgi?id=23453
Even though iterating over UTF value ranges don't make sense in general, they would work for some values including the ASCII range. Ali
Nov 03 2022
prev sibling parent reply Salih Dincer <salihdb hotmail.com> writes:
On Thursday, 3 November 2022 at 11:58:20 UTC, Paul Backus wrote:
 On Thursday, 3 November 2022 at 06:26:22 UTC, Salih Dincer 
 Looking at the source, it seems that only the numeric overloads 
 of `iota` implement `save`. I think this is probably just an 
 oversight, though, since I can't see any reason why `save` 
 wouldn't work just as well for the generic version.
The problem I'm having here seems to be chunk related. But using a template like iota!char for some reason does not affect the output result. I showed these situations in the example in the Turkish forum: https://forum.dlang.org/thread/jbklbbozmisahohouzsn forum.dlang.org SDB 79
Nov 04 2022
parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Friday, 4 November 2022 at 08:48:36 UTC, Salih Dincer wrote:
 On Thursday, 3 November 2022 at 11:58:20 UTC, Paul Backus wrote:
 On Thursday, 3 November 2022 at 06:26:22 UTC, Salih Dincer 
 Looking at the source, it seems that only the numeric 
 overloads of `iota` implement `save`. I think this is probably 
 just an oversight, though, since I can't see any reason why 
 `save` wouldn't work just as well for the generic version.
The problem I'm having here seems to be chunk related. But using a template like iota!char for some reason does not affect the output result. I showed these situations in the example in the Turkish forum: https://forum.dlang.org/thread/jbklbbozmisahohouzsn forum.dlang.org SDB 79
See Pauls response
Nov 04 2022