g++ 4.0 and typeof/operator overloading based metaprogramming

Hello everyone, I've been trying out a pre-release of g++ 4.0, and its typeof now works a lot better than the older versions. This allows it to be used for metaprogramming. As an example, I've attached a compile time factorial implemented mainly using operator overloads (it's not commented at all, but should be pretty easy to understand for most people on this list). I think it would be possible to write a metaprogramming library which would have much nicer syntax (borrowing techniques from lamba & phoenix), and integrate well with mpl. I suppose that since such a library would only work on gcc for now (or do any other compilers have a good enough typeof?), it might not be appropriate for boost, but I thought this might be of interest here anyway. Daniel

Daniel James writes:
I've been trying out a pre-release of g++ 4.0, and its typeof now works a lot better than the older versions. This allows it to be used for metaprogramming. As an example, I've attached a compile time factorial implemented mainly using operator overloads (it's not commented at all, but should be pretty easy to understand for most people on this list). I think it would be possible to write a metaprogramming library which would have much nicer syntax (borrowing techniques from lamba & phoenix), and integrate well with mpl.
You don't need 'typeof' for that kind of syntax sugar; a standard compliant compiler will suffice, see http://thread.gmane.org/gmane.comp.lib.boost.devel/77267. -- Aleksey Gurtovoy MetaCommunications Engineering

Aleksey Gurtovoy wrote:
You don't need 'typeof' for that kind of syntax sugar; a standard compliant compiler will suffice, see http://thread.gmane.org/gmane.comp.lib.boost.devel/77267.
Oh, that's very nice. I guess it could work on more compilers now as well. I think using 'typeof' has a few small advantages (lets you use operators, possibly faster compile times and maybe nicer error messages) but that looks much better. Daniel
participants (2)
-
Aleksey Gurtovoy
-
Daniel James