[Issue 10909] std.conv.to!(bool)(int): conversion from integer to bool
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 26 23:31:03 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10909
--- Comment #2 from growlercab at gmail.com 2013-08-26 23:31:00 PDT ---
(In reply to comment #1)
> The current semantics of "to!X" means that there is range validation. This
> means that something such as:
>
> "to!bool(55)" *should* trigger an overflow exception.
>
> This might sound inconvenient at first, but on the other hand, if it didn't,
> than to would just be a glorified cast to bool.
Good point, range checking should be in place so ignore that last part of the
code. If this is implemented then the following should work:
---
import std.conv;
void main() {
assert(0.to!bool == false);
assert(1.to!bool == true);
int ival = 1;
assert(ival.to!bool == true);
ival = 0;
assert(ival.to!bool == false);
}
---
Thanks,
G.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list