|
Boost : |
From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-01-06 06:16:17
>From: "David Abrahams" <dave_at_[hidden]>
> Aleksey and I are trying to think of a simple metaprogramming
> problem which we could use as a sort of "Hello World" example for
> the MPL. This seems to be a rather hard problem. Aside from being
> short, a C++ "hello, world" introduces only two library components,
> cout and endl (three if you count operator<<), the problem it
> solves, "printing something", is most programmers will want to do,
> and it gives a small rush of excitement when you see it work.
>
> However, it's hard to "see a metaprogram work" except by
> error/warning, and it's hard to demonstrate much of any practical
> use with a very small number of library components. Some of the
> simplest jobs involve numerical computation at compile-time, but I
> don't really want to show that right off the bat because:
>
> a) of the syntactic/mental overhead of using the type wrappers
>
> b) The eye is easily confused by code which mixes placeholders (e.g.
> "_1") in expressions with numeric constants (e.g. "2").
>
> Thoughts?
How about implementing one of the "classic" metaprograms, such as factorial,
or prime number finding (in credit to Erwin Unruh, who had a compile-time
prime number program as one of the first ever metaprograms in C++. :) ),
using MPL idioms? The results don't necessarily have to be printed out at
compile-time (Erwin Unruh printed the results using compiler-warnings, but
that is of course highly implementation dependent).
"Hello, world" in compile-time programming doesn't necessarily have to be
the same kind of program as in run-time programming, since the way it works
is different.
Regards,
Terje
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk