I've been hacking some C++ 2D vector and matrix classes in
a vector drawing program I'm planning to do. They are
template expression based and therefore totaly unreadable.
But they do generate kick ass code using the latest g++
Using the online snapshot compile form at codesourcery
double dotty(Vector &x, Vector &y, Vector &z)
return dot(x, y+z);
compiles to this (x86) code (using -O2 -march=pentiumpro):
movl %esp, %ebp
subl $24, %esp
movl 8(%ebp), %eax
movl 12(%ebp), %edx
movl 16(%ebp), %ecx
movl %ebp, %esp
fmulp %st, %st(2)
fmulp %st, %st(1)
faddp %st, %st(1)
which is pretty damn good for that (very readable)
sourcecode. There is none of the normal problems with
temporary objects etc.
Unfortunately i had to fight quite a lot with the template
syntax, so the code isn't very nice. It would be a lot
convertion operators were actually used when matching
arguments to template functions.
I wonder why that isn't in the C++ standard?