Yitzhak Sapir <[EMAIL PROTECTED]> writes:
> I think storing the text "Hello world!" in a vector
>
> typedef vector13_c<char,
> 'H','e','l','l','o',' ',
> 'w','o','r','l','d','!','\n'> hello_world;
>
> And then using functors to print it such as:
>
> template <class Prev, class T> struct print
> {
> static void eval()
> {
> Prev::eval();
> std::cout.put(T::value);
> }
> };
>
> fold<vector,...>::type::eval();
>
> would work as an hello world. It introduces two main concepts (fold,
> vector), shows how MPL can be used for loop unrolling (on proper
> compilers, the entire Hello world text would be unrolled into
> successive calls cout.put), and makes sense for most people as an "Hello
> world".
That's a very interesting idea!
I think I'd use mpl::for_each instead of fold<> here:
typedef vector13_c<char,
'H','e','l','l','o',' ',
'w','o','r','l','d','!','\n'> message;
struct printer
{
template <class T>
void operator()(T&) const
{
std::cout.put(T::value);
}
};
for_each<message,identity>(printer);
--
David Abrahams
[EMAIL PROTECTED] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost