Inconsistent chain (implicitly converts to int)

Salih Dincer salihdb at hotmail.com
Fri Apr 5 15:18:09 UTC 2024


Hi everyone,

Technically r1 and r2 are different types of range. Isn't it 
inconsistent to chain both? If not, why is the char type 
converted to int?

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

void main() {
   auto r1 = N!size_t(10, 1, 1);
   auto r2 = N!real(15, .5, 10);

   r1.chain(r2).writeln;
   // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10.5, 11, 11.5, 12, 12.5, 
13, 13.5, 14, 14.5]

   auto a = [97, 98, 99];
   auto b = ['d', 'e', 'f'];

   a.chain(b).writeln;
   // [97, 98, 99, 100, 101, 102]
}

struct N(T)
{
   T last, step, first;
   bool empty() => first >= last;
   T front() => first;
   auto popFront() => first += step;
}
void main() {
   auto r1 = N!size_t(10, 1, 1);
   auto r2 = N!real(15, .5, 10);

   r1.chain(r2).writeln;
   // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10.5, 11, 11.5, 12, 12.5, 
13, 13.5, 14, 14.5]

   auto a = [97, 98, 99];
   auto b = ['d', 'e', 'f'];

   a.chain(b).writeln;
   // [97, 98, 99, 100, 101, 102]
}

struct N(T)
{
   T last, step, first;
   bool empty() => first >= last;
   T front() => first;
   auto popFront() => first += step;
}
```

SDB at 79


More information about the Digitalmars-d-learn mailing list