Strange behavior of iota
bachmeier
no at spam.net
Tue Feb 15 22:24:53 UTC 2022
On Tuesday, 15 February 2022 at 22:02:13 UTC, Adam D Ruppe wrote:
> On Tuesday, 15 February 2022 at 21:48:29 UTC, bachmeier wrote:
>> writeln(iota(v.length,-1,-1));
>
> This would be like
>
> for(a = v.length; a > cast(size_t) -1, a += -1)
>
>
> That (cast(size_t) -1) is the same as thing.max, meaning a will
> never be greater than it.
>
>> Why does the first argument to iota have to be an int, and why
>> isn't there an error message when I pass something else?
>
> Yeah, perhaps when you give it that -1 as the second argument
> it should see it is signed and throw something.
After looking at the documentation and seeing CommonType!(int,
uint) is uint, I have to say that iota's behavior doesn't make
much sense.
More information about the Digitalmars-d-learn
mailing list