Iota

Salih Dincer salihdb at hotmail.com
Wed Aug 10 19:02:21 UTC 2022


On Saturday, 6 August 2022 at 15:11:28 UTC, Paul Backus wrote:
> ...because nobody ever bothered to add a `(start, end, step)` 
> overload for custom types.

We did it 😀

```d
import //sdb.container,
        std.bigint,
        std.stdio;
void main()
{
     auto f = BigInt(ulong.max);
     auto s = BigInt(10);
     auto l = f + 10;
     //iota(f, l, s).writeln;  // compile error
     iras(f, l, s).writeln;  // no problem :)
// [18446744073709551615, 18446744073709551625]
}

alias ir = inclusiveRange;
alias iras = inclusiveRange;
void inclusiveRange(T)(T Args...) if(is(T == bool)) {
   static assert(0, "\nBoolean type cannot be used!");
}
auto inclusiveRange(T = int)
(T f = T(0), T l = T(0), T s = T(1))
if(!is(T == bool)) {
   if(!l) {
     l = f;
     f = 0;
   }
   return InclusiveRange!T(f, l, s);
} /* Error:
    * operation not allowed on `bool` `this.last -= this.step`
    */

struct InclusiveRange(T)
{
   T front, last, step, term;
//...
```

The continuation of the code:

https://forum.dlang.org/post/nffqokazngtknxetiinu@forum.dlang.org

SDB at 79



More information about the Digitalmars-d mailing list