|
Boost Users : |
Subject: [Boost-users] [Units] Extension for units of data (and data rate)
From: David, Robert (NSN - HU/Budapest) (robert.david_at_[hidden])
Date: 2011-04-27 10:57:09
Hello,
I have created an extension to Boost.Units to support data sizes (bit /
byte / kilobit / etc.) and data rates (bit per sec / Byte per sec /
kbps / etc.), trying to mimic the logic behind the SI, GCS systems, so
it might be added to the library after some review and fixes. Please see
the attachment for the code (8 kB zip).
Before that, a problem has to be fixed in my implementation: If I define
the unit byte_per_second using make_scaled_unit and bit_per_second, I
get a mile-long template error about not being able to figure out the
prefix when I try to convert a quantity using that unit to string. I did
a workaround for this problem using decltype(), but that requires
including data_size.hpp and time.hpp to data_rate.hpp (although I don't
know if it is a problem), and also, it only works on compilers
supporting c++0x. You can see this workaround starting at line 40 in
boostex/units/systems/data/data_rate.hpp. If I comment back line 41, and
comment out line 44-45, the following will not compile:
quantity<byte_per_sec_unit> speed(5.0 * byte_per_sec_unit);
std::cout << speed << std::endl;
however,
auto speed = 5.0 * byte_per_sec_unit;
std::cout << speed << std::endl;
does (although only on compilers supporting c++0x auto), but prints out
"second^-1 byte" instead of "byte/second" - effectively it does not call
the name_string specialization for byte_per_sec in
boostex/units/systems/data/io.hpp. All of this works correctly with the
decltype() workaround.
So my question is: can I define byte_per_sec (kilobyte_per_sec,
megabyte_per_sec, etc.) in a c++03-compatible way?
Br, Robert
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