How to have strongly typed numerical values?
ixid
nuaccount at gmail.com
Tue Sep 4 20:11:25 PDT 2012
Using this:
struct Grams
{
size_t amount;
}
@property Grams grams(size_t amount)
{
return Grams(amount);
}
void main()
{
auto weight = 5.grams;
weight = weight + 10.grams;
}
How would you use it? I thought the point of this sort of strong
typing was to be able to carry out arithmetic using your type
that other units cannot accidentally be mixed with.
More information about the Digitalmars-d-learn
mailing list