Inconsistent chain (implicitly converts to int)

rkompass rkompass at gmx.de
Sat Apr 6 09:21:34 UTC 2024


On Friday, 5 April 2024 at 21:26:10 UTC, Salih Dincer wrote:
> On Friday, 5 April 2024 at 21:16:42 UTC, rkompass wrote:
>>
>> In the first example the int's are converted to doubles (also 
>> common type).
>> But they appear as int's because writeln does not write a 
>> trailing .0.
>
> But it doesn't work as you say! I even tried it on an older 
> version and got the same result.
>
> SDB at 79

I checked:

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

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]
   r1.chain(r2).map!(x => typeid(x)).writeln;
   // [real, real, . . . , real]
}
```
and it seems to work as I said.


More information about the Digitalmars-d-learn mailing list