How to have strongly typed numerical values?

Ali Çehreli acehreli at yahoo.com
Tue Sep 4 18:54:02 PDT 2012


On 09/04/2012 05:55 PM, Nicholas Londey wrote:

 > I could easily implement my own as I have done in C++ in the
 > past but assume there is a standard implementation which I would prefer.
 > Any help or links to examples much appreciated.

UFCS enables some interesting syntax:

struct Grams
{
     size_t amount;
}

@property Grams grams(size_t amount)
{
     return Grams(amount);
}

void main()
{
     auto weight = 5.grams;
}

C++11 brings similar conveniences as well.

Ali



More information about the Digitalmars-d-learn mailing list