Boost logo

Boost Users :

Subject: [Boost-users] [units] check if quantities are convertible one into the other
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-12-15 13:12:40


Hi,

 I have two (or more) default (or user defined) system units. For certain
operations I assume that one quantity in one system can be converted into
another quantity in some other system with the same dimension. What
conversions are allowed depend on the included headers at best.

What is the best way to check at compile time that one quantity can be
converted into another?

For example, I have this function that sums two quantities with the same
dimension and returns the result of the left term. The function assumes that
qright is convertible to qleft. If it is not convertible I would like to
catch the error early with static_assert (or even with some enable_if to
ignore the function)

    template<class Dimension, class LeftSystem, class RightSystem>
    quantity< unit<Dimension, LeftSystem> > sum_to_left(
        quantity< unit<Dimension, LeftSystem> > const& qleft,
        quantity< unit<Dimension, RightSystem> > const& qright
    ){
        return boost::units::operator + (qleft, quantity< unit<Dimension,
LeftSystem> >(qright));
    }

Thank you,
Alfredo



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net