On Friday, 5 April 2024 at 16:05:20 UTC, H. S. Teoh wrote:
On Fri, Apr 05, 2024 at 03:18:09PM +0000, Salih Dincer via Digitalmars-d-learn wrote:
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?
[...]

It's not inconsistent if there exists a common type that both range element types implicit convert to.

The real problem is the implicit conversion of char to int, which I have been against for a long time. Walter, however, disagrees.


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

  a.chain(b).map!(chr => chr.to!char).writeln;
  // abcdef
```

Nice, there is a solution that requires memory allocation, but it still makes you think!

However, they can fix this in Phobos3 because now we have this too: https://dlang.org/changelog/2.108.0.html#range_predicate_element

PS. I think I unintentionally made a chain by repeating the source code above, sorry :)

SDB@79

Reply via email to