yank unary '+'?

Brad Roberts braddr at puremagic.com
Sun Dec 6 21:54:47 PST 2009


Andrei Alexandrescu wrote:
> bearophile wrote:
>> Walter Bright:
>>
>>> Think of it like the "bool" operator overload. bool gives a direct
>>> way for user defined times to be tested for if statements, etc.
>>> Similarly, U+ gives a direct way for user defined types to be
>>> converted to their most desired arithmetic type.
>>
>> I'd like opBool in D, for example to implement multiprecision numbers
>> that can be used as integers in: if (somenumber) {...
> 
> Unfortunately experience with C++ has shown that things look simpler
> than they are. If opBool is an implicit conversion to bool, then all
> sorts of weird expressions are allowed. That's why conversion to bool is
> flat out unrecommended in C++. Instead, various libraries found
> alternate ways to allow testing with if without compromising things too
> much. Loki uses conversion to an opaque pointer type. Boost uses
> conversion to a pointer to member. The standard itself uses, I think,
> conversion of iostreams to void*.

Isn't one of the key problems that bool conversion introduces is the follow on
conversion to integral types?  If implicit bool -> integral conversion wasn't
allowed, T -> bool conversion would be less problematic, no?



More information about the Digitalmars-d mailing list