Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-06-08 12:46:16

"Janek Kozicki" <janek_listy_at_[hidden]> wrote in message
> Carlo Wood said: (by the date of Thu, 8 Jun 2006 16:06:47 +0200)
>> std::cout << pqs::ios::litres << volume;
>> outputting 'litre' instead of 'm3', but the number of possible
>> formats are endless, and so are the preferences of different people.
> Im accustomed to using decimetre^3, always abbreviated as dm^3, which
> equals exactly 1 litre (because it's 10x10x10 centimeters = 1x1x1
> decimeter )

Although liter is equivalent to 1 dm^3, technically its not an SI unit. Its not
in the review version of PQS, but it is possible to add a liter unit to volume
header and get output as

1 L

or whatever is preferred... I just did this in my local version of PQS.

The sequence of steps is

1) In <boost/pqs/meta/components/of_volume.hpp>

    Add a typedef for the liter in the incoherent_unit struct (starts at line

            typedef meta::unit<
> liter;


In <boost/pqs/t1_quantity/types/volume.hpp>

    Add the typedef for liter to the other member typedefs:

         typedef t1_quantity<
            typename incoherent_unit::liter,
> liter;

3) In <boost/pqs/t1_quantity/types/out/volume.hpp> add the stream output
overload for the liter unit:

    operator <<(
        std::ostream & os,
        os << "L";
        return os;

Check it works:

#include <boost/pqs/t1_quantity/types/out/volume.hpp>
using boost::pqs::volume;

int main()
   volume::liter v(1);
   std::cout << v <<'\n';
   volume::m3 v1 = v;
   std::cout << v1 <<'\n';


1 L
0.001 m3

Because liter isnt an SI unit you would need to add cL and mL in the same way (I
guess that would be the next question!)

Andy Little

Boost list run by bdawes at, gregod at, cpdaniel at, john at