On 09/20/2013 11:11 PM, Steven Watanabe wrote:
(Other than the obvious typos.) I also have
no idea what you mean by "varying types, not typenames"
Example:
boost::units::si::meter is a constant of type
unit.
boost::units:si::watts is a constant of type
unit.
Since they are constants, any template would have to be of the form
template
struct mapper
{
static const MyStruct value;
};
However, since unit_t is variant - unit,
unit, etc. - it has to be a template
parameter as well - and come before the constant.
So now the template would have to be:
template < typename dim_t, typename sys_t, const
boost::units::unit &units>
struct mapper
{
static const MyStruct value;
};
But now those paramters have to be specified in the use.
The other approach would be to use a function:
template < typename dim_t, typename sys_t>
const MyStruct &Map(unit const &value);
which isn't bad on invocation:
const MyStruct &x = Map(meters);
but gets more difficult on definition
template <> const MyStruct
&Map(unit const &)
{
static const MyStruct mymeters(/* parameters */);
return mymeters;
}
template <> const MyStruct
&Map(unit const &)
{
static const MyStruct mywatts(/* parameters */);
return mywatts;
}
since for every type you have to go look up the full dimensionality.
Now, were there some base type for boost::units::unit
class unit_base
{
};
template
class unit: public unit_base
{
}
Then this whole thing would be simpler, as they my code could use the
base type to key off. (I would have to handle the fact there are
multiple definitions in the library, e.g. meter/meters/metre/metres).