|
Re: My Most Important C++ Aha! Moments...Ever
|
Posted: Sep 7, 2006 9:27 AM
|
|
One of my biggest aha! moments with C++ came when I learned that you could do metaprogramming in C++ (from Todd Veldhuizen's work: http://osl.iu.edu/~tveldhui/papers).
I was working with things like 3D graphics at the time, and compilers weren't that very good to do things like automatical loop-unrolling and similar optimisations, so I was thrilled to learn that you could actually make the compiler do this, yourself... As well as other program transformations and computations.
As is now well known, C++ happens to have a Turing-complete language at compile-time, which makes theoretically any transformation or computation - where the data is available at compile-time - possible.
You may even do it partially at compile-time, partially at run-time, and take advantage of any information existing at compile-time, to make execution more efficient or safe (the latter coming more from static typing, than metaprogramming).
In a sense, the C++ template system - with its non-type template parameters - is a little like a dependent type system.
|
|