|
Boost : |
From: Matthias Schabel (boost_at_[hidden])
Date: 2007-02-07 12:42:40
ISWT
>>> I would suggest that you have a
>>> pod_quantity for defining the various
>>> constants so that they can be safely
>>> used during the dynamic initilization
>>> phase.
>
> template<class Unit, class T = double>
> struct pod_quantity {
> //like quantity but without constructors/assignment operators
> T val_;
> };
>
> constants.hpp
>
> pod_quantity<si::velocity> c = { 299792458 };
The problem with this is that you lose the type-safety of forcing
explicit value+unit
construction of quantities. That is, if someone decided to express
the constant in
cgs units instead and just did a global search and replace for si:: -
> cgs:: the code
would suddenly have a bug because there would be no way for the
compiler to know
that the specified constant value was meant to be in SI units. By
requiring constructs
like
quantity<si::velocity> c(299792458*si::meters/si::second);
you would get an error here:
quantity<cgs::velocity> c(299792458*cgs::meters/cgs::second);
because there is no meter defined in cgs. There has to be a better
solution to the
dynamic initialization problem...anyone?
Matthias
----------------------------------------------------------------
Matthias Schabel, Ph.D.
Assistant Professor, Department of Radiology
Utah Center for Advanced Imaging Research
729 Arapeen Drive
Salt Lake City, UT 84108
801-587-9413 (work)
801-585-3592 (fax)
801-706-5760 (cell)
801-484-0811 (home)
matthias dot schabel at hsc dot utah dot edu
----------------------------------------------------------------
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk