From: Jan Langer (jan_at_[hidden])
Date: 2004-01-07 14:07:11
Andy Little wrote:
>>unit::Speed s = 2 * unit::m / unit::s;
> My syntax in my physical_quantities type for this is:
> q_velocity::m_div_s s(2);
i know. but there is imho nothing wrong with both syntaxes. the first
one constructs a quantity from another one with a non-explicit ctor like:
quantity (quantity const &q2);
and your syntax uses a ctor like:
explicit quantity (value_type v);
i really dont see a problem. the above syntax would also allow
constructions from more complex expressions.
> IOW the units are part of the type declaration.
> The q_ prefix is to prevent name collisions.
> Unless I'm missing something it is also as legible if not more so and
> if operator *() is actually a runtime multiplication in the top example
> over which there seems to be some confusion, better in raw performance
> (no runtime multiplication involved in my declaration).
> which I had thought was a critical factor to many.
yes but there is nothing which cannot be optimized away. meter is a
constant and 2 too. but the whole dimensions lib will not work without
sufficient compiler optimizations, so i dont think this will mean a problem.
actually its similar to the case of the sine function.
you have to write
double v = 2 * sin (x);
which is imho very similar to
length l = 2 * meter;
-- jan langer ... jan_at_[hidden] "pi ist genau drei"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk