Millimeters in boost::units

后端 未结 3 1494
鱼传尺愫
鱼传尺愫 2021-01-05 09:55

I want to use boost::units for some SI metrics. However our code mostly deals with millimeters and instead of using

quantity value = 1*milli*m         


        
3条回答
  •  孤街浪徒
    2021-01-05 10:42

    C++11 is indeed the easiest solution. You could do

    static const auto millimeter = milli * meter;
    

    or

    auto operator"" _mm (long double val) -> decltype(val * milli * meter)
    {
         return val * milli * meter;
    }
    

    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 replace auto by int and read the compiler message.

提交回复
热议问题