User defined literals in C++11 and D
Walter Bright
newshound2 at digitalmars.com
Sat Feb 4 12:39:32 PST 2012
On 2/4/2012 9:08 AM, bearophile wrote:
> About Bjarne Stroustrup's talk "C++11 Style":
>
> I have appreciated (slide 22, at about 26.22) the stress on SI units, to use
> the type system and the new C++11 feature to some avoid some bugs with zero
> run-time cost. D requires a less natural syntax for them.
C++ allows for user-defined literals, such as:
30sec
The D equivalent would be:
sec!30
The C++ version is a bit hackish in that it relies on sec being a global
function. There's no opportunity for scoping, encapsulation, etc., and if two
different libraries defined overloads for sec on int, you're just stuck.
We'll see how this unfolds in practice.
The D version does not have these issues (and is not even a special feature -
it's just another way to use an existing feature).
More information about the Digitalmars-d-announce
mailing list