1 matches bool, 2 matches long

Paulo Pinto pjmlp at progtools.org
Mon Apr 29 11:13:37 PDT 2013


Am 29.04.2013 19:10, schrieb Steven Schveighoffer:
> On Sat, 27 Apr 2013 13:27:39 -0700, Walter Bright
> <newshound2 at digitalmars.com> wrote:
>
>> On 4/26/2013 11:04 PM, Steven Schveighoffer wrote:
>>> I think the issue (and I am firmly in the foo(1) => long camp) is
>>> that bools are
>>> considered better integers than actual integer types (or even
>>> floating point
>>> types for that matter).  I agree that bools can be implicitly cast to
>>> and from
>>> integers, as a last resort.
>>
>> The overload system in D is explicitly not based on "better". (The C++
>> "better" overloading system is for functions, but not for templates.)
>> The D overload system is based on partial ordering, which is the same
>> as what C++ uses for templates.
>>
>> I don't know for a fact, but I'm pretty sure the partial ordering
>> scheme that C++ selected for templates, which came along many years
>> later, was picked because people realized it was better (and more
>> mathematically robust and defensible).
>>
>> One of the problems with a "better" matching system is handling
>> functions with multiple parameters, each with their own "better"
>> match. (The C++ Standard devotes a great deal of complex text to this,
>> it boils down to a bunch of rather arbitrary decisions.) Partial
>> ordering solves this neatly and consistently.
>>
>> As one who implemented C++'s better matching system, I can confidently
>> state that the partial ordering scheme is FAR better overall.
>
> I think you are inventing a strawman problem that this bug solves.
> There is no need for a "Better" scheme, partial ordering works great,
> and so do true and false.
>
> bool isn't an integer.  It can implicitly cast to an integer, but that's
> it.  Once we implement that rule, everything falls into place.  If you
> want to pass a "true" boolean literal, use true.  If you want to pass a
> "false" boolean literal use false.  Using 1 and 0 may be convenient, and
> may also be valid, but when it matches an integral type as well as bool,
> then it's ambiguous.
>
> -Steve

Fully agree, I still not understand what is the issue to support the 
boolean strong typing other languages do offer.

--
Paulo


More information about the Digitalmars-d mailing list