Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > computation at compile time i.e. compile time functions usingtemplates

Reply
Thread Tools

computation at compile time i.e. compile time functions usingtemplates

 
 
Carter
Guest
Posts: n/a
 
      03-04-2009
Hi,

I am a bit new when it comes to C++ and I wasnt sure how to go about
doing this. How does one compute values at compile which can be
plugged into a static const value using a template. I remember seeing
in a book I no longer have some method for doing this. For example the
book gives a method for computing at compile time the value of
Fibonacci sequence where the value is generated by the compiler.
Unfortunately I seem to have misplaced the book.

Thanks in advance,

Carter.
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      03-04-2009
Carter wrote:
> I am a bit new when it comes to C++ and I wasnt sure how to go about
> doing this. How does one compute values at compile which can be [...]


http://en.wikipedia.org/wiki/Template_metaprogramming

There's an example for compile-time factorial computation.

Cheers!
SG
 
Reply With Quote
 
 
 
 
Carter
Guest
Posts: n/a
 
      03-04-2009
On Mar 5, 12:13*am, Jeff Schwab <j...@schwabcenter.com> wrote:
> Carter wrote:
> > I am a bit new when it comes to C++ and I wasnt sure how to go about
> > doing this. How does one compute values at compile which can be
> > plugged into a static const value using a template. I remember seeing
> > in a book I no longer have some method for doing this. For example the
> > book gives a method for computing at compile time the value of
> > Fibonacci sequence where the value is generated by the compiler.
> > Unfortunately I seem to have misplaced the book.

>
> See C++ Template Metaprogramming, by Abrahams and Gurtovoy. *Basically,
> you just define a template to instantiate itself recursively, and
> specialize for the base case.


Thanks both.
 
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
where can I find good samples for efficient computation of matrix multiplication? walala VHDL 2 03-24-2010 10:06 AM
GPS : Basic pseudo-distance computation le Cl? VHDL 15 04-11-2009 09:22 AM
display computation time in IRB Jason Lillywhite Ruby 4 03-20-2009 10:59 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



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