Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2004-01-07 05:44:42

Dan W. wrote:
> David B. Held wrote:
> I'd go for
> s = 2 m/s; //if at all possible, and would try really hard

Oh, I thought that the missing * was an accident. The above would really
be cool, but it's impossible. (Granted, let 'm' be a macro and it could
work, but you don't want that, do you?)

> Re.: Name collisions: I don't give a damn; the compiler'll catch'em.

Nope, only if you are lucky. I guess that those that use a unit library
are interested in reliable and safe code. And a unit library is supposed
to protect you from stupidities like:

speed s = 2 * s;

Sadly, C++ allows the above...

> In any case, we're talking application of the library, not the library
> itself, when we speak of what names to use for what.
> Now, would there be any way on Earth or Mars to enable a syntax like
> above? --i.e. no * at all. I know there's no blank-space operator that
> we can overload .. :) ..
> How about starting lines using units with a $ sign...
> $ s = 2 m/s;
> then
> #define $ spirit_of_units()=

Illegal AFAIK, you can't define $ portably. Just an idea:
unit::make(value)[unit], e.g.:

unit::speed s = unit::make( 42 )[m/s];

and possibly the seriously overused _:

#define _(x) unit::make(x)

unit::speed s = _( 42 )[m/s];

and at least _ without ( is not tainted. Maybe possible...

Regards, Daniel

Daniel Frey
aixigo AG - financial solutions & technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web:

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