user defined literals
Walter Bright
newshound2 at digitalmars.com
Fri Mar 25 10:28:55 PDT 2011
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.
More information about the Digitalmars-d
mailing list