« Return to Thread: Units of data

Re: Units of data

by Matthias Schabel-2 :: Rate this Message:

Reply to Author | View in Thread

> void foo()
> {
> using boost::units::quantity;
> using namespace boost::units::data_capacity;
>
>        //Both of these fail with the message that there is no
> conversion to the destination
>        //type because the construcor is explicit
> quantity<data_capacity> compressed_size = 1000 * bytes;
> quantity<data_capacity, int> compressed_size2 = 1000 * bytes;

Implicit conversion is not allowed, and default value type is double -  
try :

quantity<data_capacity>      compressed_size(1000.0*bytes);
quantity<data_capacity,int> compressed_size2(1000*bytes);


> //Succeeds but gives a horribly long warning about conversion from
> 'double' to 'const int'
> //at file 'boost/units/detail/conversion_impl.hpp(342)', reference to
> class template instantiation at
> //boost/units/quantity.hpp(182)
>       quantity<data_capacity, int> compressed_size3(1000 * bytes);
> }

If I remember correctly, this stems from the use of double precision  
in the conversion code. I think it would be difficult to get rid of  
this - most computations involving unit conversions do not involve  
exact integer arithmetic...

Matthias
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

 « Return to Thread: Units of data