Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-01-06 17:34:14


>From: "Yitzhak Sapir" <yitzhaks_at_[hidden]>

> 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".

I was thinking of something like this, too, before I sent the first posting.
However, I wondered if it might be too "far out" :) as an example, i.e. fun,
but perhaps not much practical use. For fun, I posted a program that did
something similar, a few months ago. I didn't find it in the archive, now,
but from my own copy, the main() looked like this:

int main()
{
typedef String<'H','e','l','l','o',',',' '>::Result Str1; // Str1="Hello,"
typedef String<'w','o','r','l','d','!'>::Result Str2; // Str2="world!"

typedef Loki::TL::Append<Str1,Str2>::Result Text; // Text = Str1 + Str2

insert<Text>(); // Write the characters in the typelist to the string "str"

std::cout << str << '\n'; // Prints "Hello, world!"
}

Regards,

Terje


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk