On 4/25/2013 10:49 PM, Ali Çehreli wrote:
It certainly behaves that way but it isn't an integer type and that's why it is
unintuitive.

But it is an integer type.

bool is a type with two values: false and true with the following conversion 
rules:

false -> 0
true -> 1
0 value -> false
non-zero value -> true
0 literal -> false

The following are the problematic ones:

1 literal -> true
non-zero and non-one *literal* -> Not a bool!

That last rule is the problem. Since we cannot get rid of the last rule, to be
consistent, we should make literal 1 match an integer type better than bool.

Whether it's a problem or not depends on one's perspective.

The next issue is the notion of a "better" match. This notion is very complex in C++, and still produces odd results. Very few people can explain how it works - it's kind of shoot and hope you hit the target.

D tries very hard to avoid the notion of a "better" match. It goes with an exact match, followed by one with implicit conversions. All implicit conversions are considered equally good. Ambiguity is resolved by invoking "partial ordering", which was explained elsewhere in this thread. Partial ordering does not at all consider "better" matches.

Once you venture down the path of "better" matches, it's all roses at first, but look at where C++ wound up with it. It didn't intend to arrive there, it inevitably arrived there.

The real issue is do you want to have the implicit conversions:

0 => false
1 => true

or would you require a cast?

Reply via email to