I want to use boost::units for some SI metrics. However our code mostly deals with millimeters and instead of using
quantity<length> value = 1*milli*meter;
we would prefer something like
quantity<length> value = 1*millimeter;
However I am not sure how to define "millimeter" (without using #define).
Secondly, what is the overhead in using prefixed units?
Update: This needs to run without C++11 features (i.e. no UDL)
I am using the following approach:
C++11 is indeed the easiest solution. You could do
or
There should be no performance penalty as long as you are not converting to other prefixes. And even if you do it should be neglible.
If you don't want to use C++11 you'd need to find out the corresponding type of the expression
milli * meter
, though you could just replaceauto
byint
and read the compiler message.If you have a C++11 capable compiler you could use User Defined Literals for defining your units.
You can use that like so: