On Tue, Nov 13, 2018 at 02:12:30AM +0000, 12345swordy via Digitalmars-d-announce wrote: > On Monday, 12 November 2018 at 21:38:27 UTC, Walter Bright wrote: [...] > > The underlying issue is is bool a one bit integer type, or something > > special? D defines it as a one bit integer type, fitting it into the > > other integer types using exactly the same rules. > > > > If it is to be a special type with special rules, what about the > > other integer types? D has a lot of basic types :-) > > Ok, you don't want to introduce special rules for integers, and that > understandable. > > However there needs be a tool for the programmer to prevent unwanted > implicit conversation when it comes to other users passing values to > their public overload functions.(Unless there is already a zero cost > abstraction that we are not aware of). [...]
This discussion makes me want to create a custom bool type that does not allow implicit conversion. Something like: struct Boolean { private bool impl; static Boolean True = Boolean(1); static Boolean False = Boolean(0); // For if(Boolean b) opCast(T : bool)() { return impl; } ... } Unfortunately, it wouldn't quite work because there's no way for built-in comparisons to convert to Boolean instead of bool. So you'd have to manually surround everything with Boolean(...), which is a severe usability handicap. T -- People tell me that I'm skeptical, but I don't believe them.