user defined literals

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Mar 25 13:02:00 PDT 2011


On 3/25/11 10:28 AM, Walter Bright wrote:
> On 3/25/2011 8:14 AM, Trass3r wrote:
>> Units, I think.
>> auto dist = 1km;
>> sin(90deg);
>
> One difficulty with the C++0x approach is that the operator"" needed to
> implement it is a global function. Global functions work fine until you
> wind up with two km functions with different purposes, and then things
> just don't work anymore.
>
> In D, you can have user defined literals of the form:
>
> km!1
> km!"1"
> km(1)
>
> implemented using CTFE. Adding yet another syntax for it seems to be of
> marginal utility.
>
> C++0x needed to add the new syntax because its CTFE ability is minimal,
> and C++ template metaprogramming cannot process strings.

All good points. I should also add that the user-defined literal syntax 
is considered an albatross in certain C++ circles.

Andrei


More information about the Digitalmars-d mailing list