# Boost :

From: Andy Little (andy_at_[hidden])
Date: 2005-10-20 14:04:39

"Deane Yang" wrote

> It could be just me, but I'd like to be at least warned if I manage to
> write code that contained
>
> quantity_in_inches + quantity_in_meters
>
> or even
>
> quantity_in_millimeters - quantity_in_kilometers
>
> Both to me are signs that something went wrong.

Actually I had just a problem the other day where the conversion came in handy.
i wanted to find postage for an item to go on ebay. I had a kitchen scales that
works in lb and oz, and which was also not adequte to weigh the item which was
around 15 kg. in weight. So I got a plank of wood and put one end to the floor
and the other to the scales. Then I put the ebay-item on some way down the wood
so I didnt max out the scales.
Then I did a quick C++ program with pqs library to get the result. It sure was
easy not having to do all the conversions by hand. Heres the program:

#include <pqs/pqs.hpp>
int main()
{
pqs::length::m L1(1.57); // ebay_item disance along beam to scale
pqs::length::m L2(.47); // ebay-item distance to beeam end on floor
pqs::length::m L = L1 + L2; // total beam length
pqs::mass::kg m1 = pqs::mass::lb(9) + pqs::mass::oz(6); // mass read by
scales with item
pqs::mass::kg m2 = pqs::mass::lb(2) + pqs::mass::oz(10); // mass of beam
only
pqs::mass::kg m = m1 - m2; // mass on scales to due ebay-item
pqs::mass::kg result = m * L / L2; // scale by moment
std::cout << result <<'\n';
}

This also occurs with user input which often requires a conversion from e.g
imperial units to S.I. units.

cheers
Andy Little