Boost logo

Boost :

From: Msk_at_[hidden]
Date: 2001-06-22 14:23:26

Would there be any interest in a small domain library for
boost that handles dimensions (e.g. length, mass, power)
and units (e.g. meters, feet, furlongs) of physical

There is a "rough draft" implementation of such a library
at The
documentation right now just consists of comments in the
main.cpp file, which gives the general flavor of how it
can be used, and a file that outlines the design goals.

The library's main purpose is to provide compile-time
type-safety for constants, variables, and expressions. This
will prevent you from doing things like adding 2 meters to
3 kilograms, or passing a density to a procedure that expects
a specific volume. In addition, it also provides a clean syntax
for doing unit conversions, so that adding "2 meters +
3 feet" does the right thing. (It will *not* prevent you
from adding "2 pounds of garlic + 1 pound of chocolate",
even though that may be an equally foolish thing to do,
since the dimensions are compatible.) Of course it uses
templates and inlines to eliminate as much runtime overhead
as possible. (The first preliminary performance test indicated
that with optimization turned on there is zero overhead.)

I would appreciate feedback on three main questions:

1) Is this appropriate for boost? I would expect it to be
useful in almost any problem domain involving engineering,
physics, chemistry, etc. -- and let's not forget Mars
probes. :-(

2) Has this already been done? The web is awash with
interactive unit-converters, but I've found few libraries
aimed at programmers, and none that use C++ templates.

3) Does anyone see any fatal flaws in the general approach,
or is there an obviously better/simpler way to do this?
I've proposed an article about this to C/C++ Users Journal
and would prefer that any embarrassing blunders or oversights
be exposed on the boost list rather than in print. :-)

If there is any interest in something like this, I will clean
up the code a bit and then upload it into the boost files area.

- Michael Kenniston

Note 1: The code has been compiled under g++ 2.95.3-4(Cygwin).
Getting it to build under MSVC++6 will take some effort; I hope
to get that working someday but have not yet had time to find
work-arounds for all the MSVC template problems this library tickles.

Note 2: I will be out of email contact for most of next week,
so please don't be offended if my response to your comments
is delayed until Sat June 30.

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