David Abrahams (da**@boost-consulting.com) wrote:
: Readers of this newsgroup might like to know that Aleksey Gurtovoy and
: I have written a book titled _C++ Template Metaprogramming: Concepts,
: Tools and Techniques from Boost and Beyond_. The book has recently
: entered copyediting, and will be published by Addison Wesley in this
: Fall. If you're interested you can peruse some sample chapters at
:
http://boost-consulting.com/mplbook.
A bit tangential, but I skimmed one of your chapters (I'll read it
properly when I buy the book) and noticed you had an example using
templates to model physical quantities with dimensions. I read a
recent(-ish) article on doing the same thing in CUJ, which raised
a question which wasn't answered there, nor I think in your chapter.
Having not raised it with the CUJ author, I'll raise it here instead.
Basically whilst most mathematical functions (sin for example) are
straightforward, they only apply to dimensionless quantities, and
a few (abs for example) could be applied to any quantity, what about
sqrt? This is meaningful for any quantity with all even dimensions
with return type of those dimensions halved. And there are plenty
of physics formulae of this type. Can sqrt be made to work easily
and properly with compile time failure as should happen?
(Having got sqrt to work, it might be worth adding a cube root as
there are some cases of it - Kepler's third law for one, with
proper factor from Newton. Fourth root occurs, but repeated sqrt
will do that. Anyone ever seen a fifth root?)