Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] check if quantities are convertible one into the other
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-12-15 13:36:58


AMDG

On 12/15/2010 10:12 AM, alfC wrote:
> 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));
> }

The ability to test for a conversion is liable to result in
ODR problems. On the other hand, the errors are
pretty horrendous right now. This is a fairly common
problem. Could you file a trac ticket. I'll try to make the
error more readable.

In Christ,
Steven Watanabe


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