|
Boost : |
From: Steven Watanabe (steven_at_[hidden])
Date: 2007-03-29 13:44:57
AMDG
Lewis Hyatt <lhyatt <at> princeton.edu> writes:
> The only problem with that is it would require a separate check for all
> different types of units in use, even though each check was conceptually
> doing the same thing.
>
> I guess it would be a simple matter for the user to derive a new
> template from quanity<Q,T> for the sole purpose of adding the static
> assert, so perhaps the library itself doesn't need to be concerned with
> this.
How about:
template<class T, class Unit, class Y>
T technically_nonportable_quantity_cast(quantity<Unit, Y>& q) {
BOOST_STATIC_ASSERT(sizeof(quantity<Unit, Y>) == sizeof(T));
return(reinterpret_cast<T>(q));
}
template<class T, class Unit, class Y>
T technically_nonportable_quantity_cast(quantity<Unit, Y>* q) {
return(&technically_nonportable_quantity_cast<
typename boost::remove_pointer<T>::type&
>(*q));
}
//overloads for const quantity
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk