|
Boost : |
Subject: Re: [boost] Units of data
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-07-02 16:13:28
On Thu, Jul 2, 2009 at 2:07 PM, Steven Watanabe<watanabesj_at_[hidden]> wrote:
> AMDG
>
> Zachary Turner wrote:
>>
>> Thanks for your help so far! I know I'm probably just making this too
>> difficult, but it's still not working. I guess I should just post a
>> complete sample so that we can eliminate the snip factor from the list
>> of possible causes (I put them in the boost namespace for the sake of
>> consistency but the same problem arises regardless).
>>
>> <snip>
>> 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 between different units is not allowed.
> Try
> quantity<data_capacity> compressed_size(1000 * bytes);
Thanks. The confusion came from the fact that the syntax I was trying
was being used in some of the examples. But there is something
different about those examples, so that's why it wasn't working. One
of the trig examples has a line:
quantity<plane_angle> theta = 0.375*radians;
for example. I suppose it's due to the fact that radians are the
"primary" unit for this dimension?
That aside, I still think something isn't exactly right. Ultimately I
need to be able to print these quantities in different units (for
example, if I'm transferring data at 100MB/s I don't want to print
this in bits / second). All of these seems to only allow printing of
a quantity in its base unit, which here is defined to be bits. I'd
like to be able to do something like:
quantity<capacity> q = 2180321.0 * bytes;
std::cout << q * megabytes << std::endl;
or slightly more complicated,
quantity<capacity> q = 1.432 * gigabytes;
quantity<time> t = 1.5 * hours;
std::cout << (q/t) * (megabytes/minute) << std::endl;
std::cout << (q/t) * (kilobytes/second) << std::endl;
and have it print:
2.07931614 MB for the first example,
and
16.2929778 MB / minute
278.066821 KB / second
for the second example
It seems like this should "just work" since I've defined them all as
scaled based units, but instead the first example just prints
1.74426e+007 b MB
which means all its doing is formatting it as bits and then appending "MB".
Is this possible short of making one system for each type I want to
convert between?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk