C++ Template Metaprogramming

D

David Abrahams

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.
 
C

Chris Dearlove

David Abrahams ([email protected]) 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?)
 
M

Martin Eisenberg

Chris said:
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?

Should it? What about measuring power in volts/sqrt(hertz)?
The issue might get rather hairy in the general case.


Martin
 
R

Richard Herring

Martin said:
Should it? What about measuring power in volts/sqrt(hertz)?

Speaking as a physicist, yuk. That must be something engineers do. Power
spectral density in volts^2/Hz is just about permissible, with
appropriate assumptions about the impedance.
The issue might get rather hairy in the general case.

True. What do we mean by the principal value of a symbolic square root?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top