Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ Template Metaprogramming

Reply
Thread Tools

C++ Template Metaprogramming

 
 
David Abrahams
Guest
Posts: n/a
 
      07-14-2004

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.

--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
 
Reply With Quote
 
 
 
 
Chris Dearlove
Guest
Posts: n/a
 
      07-15-2004
David Abrahams () 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?)

 
Reply With Quote
 
 
 
 
Martin Eisenberg
Guest
Posts: n/a
 
      07-15-2004
Chris Dearlove wrote:

> 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

--
Quidquid latine dictum sit, altum viditur.
 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      07-16-2004
In message <>, Martin
Eisenberg <> writes
>Chris Dearlove wrote:
>
>> 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)?


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?

--
Richard Herring
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why and when Template Metaprogramming Rock Johnson C++ 9 06-13-2005 03:03 PM
Using template metaprogramming to generate a composite class withID derived from components Michael Andersson C++ 0 05-02-2005 12:14 PM
Giving proper credit to 'template metaprogramming' Sarah Thompson C++ 2 04-23-2004 07:06 PM
Template metaprogramming = interpretation Dave C++ 12 12-26-2003 12:12 PM
Sorting via template metaprogramming - critique requested Dave C++ 0 12-12-2003 08:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57