user defined literals

Trass3r un at known.com
Fri Mar 25 08:14:26 PDT 2011


Steven Schveighoffer Wrote:
> What is the need for this?  Just to replace complex(0, 5) with 5i?  I  
> don't see the huge benefit.
I didn't claim it was of "huge" benefit. It's just some slight syntactic sugar.
Furthermore I didn't mean to praise its usefulness. I was actually asking about practical issues that could arise if it _was_ implemented the way I presented.


> I simply find the complication of the language is not worth the benefits.
This is more towards my question. Please elaborate how this complicates the language.


> Also, complex is the clear and obvious beneficiary
Yep, though I think complex literals would still better be handled by the compiler specifically so that 5 + 3i is transformed to Complex(5,3) rather than 5 + Complex(0, 3)
But keeping complex literals in dmd as syntactic sugar beyond the grave of complex types is another story.

> What are other use cases?  BigXXX for sure, but Rational  
> probably cannot be covered by this since you need two numbers.
Units, I think.
auto dist = 1km;
sin(90deg);


More information about the Digitalmars-d mailing list