yank unary '+'?

Walter Bright newshound1 at digitalmars.com
Sun Dec 6 15:15:13 PST 2009


Andrei Alexandrescu wrote:
> Walter Bright wrote:
>> Andrei Alexandrescu wrote:
>>> Is there any good use of unary +? As an aside, Perl programs do use 
>>> it occasionally for syntactic disambiguation :o).
>>
>> An internet search reveals:
>>
>> 1. symmetry
>>
>> 2. compatibility with C and many other languages that use it
>>
>> 3. used with operator overloading to convert a user defined type to 
>> its preferred arithmetic representation (a cast can't know what the 
>> 'preferred' type is)
>>
>> 4. to create DSL languages, like Spirit, as Kenny points out
>>
>> 5. to coerce default integral promotion rules (again, cast(int) won't 
>> always produce the same result)
>>
>> 6. to visually emphasize that a literal is positive
>>
>> I say leave it in.
> 
> I am completely underwhelmed by 1-6 and have strong arguments against 
> each, but "frankly, my dear" I have bigger problems than that. I have 
> exactly zero valid reasons I could mention in TDPL, and that's my litmus 
> test. I find the operator utterly useless. If '+' stays in, then call it 
> horsetrading but the occasionally useful '^^=' must also be in.

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.



More information about the Digitalmars-d mailing list