Boost logo

Boost :

From: Jason House (jhouse_at_[hidden])
Date: 2003-03-28 09:16:18


Terje Slettebø wrote:
>
> >From: "Jason House" <jhouse_at_[hidden]>
>
> > I had 2 thoughts today...
> >
> > 1. Is it at all useful/possible to use a lambda-like notation?
>
> In what way? Could you have given a rough syntax-example?
>
> An example in BLL is:
>
> std::for_each(v.begin(), v.end(), std::cout << _1 << '\n');

Thinking about it more, I don't know how doable it is for the first 3
parameters...

But what about:

/* brain dead function to serve as example */
std::string printable(char z) {return z=0?"\0":std::string(z);}

char x[7] = "foobar";
std::cout
   << io_format<char[N]>("{", "}", ", ", "'" << printable(_1) << "'")
   << "x = " << x;

output:
x = {'f', 'o', 'o', 'b', 'a', 'r', '\0'}

alternates like (printable(_1) or just "'" << _1 << "'" would also work.

That makes the visitor possible, but also makes the inspiring case for
the extra inputs to io_format be a little more readable...

My original thoughts for the first 3 parameters was something like
io_format<_>("start" << _1 << "middle" << _2 << "end")
But I think that deciphering that properly in code would be tough, and
might not actually provide any extra power (for the first 3 parameters).
The only way that I see to get extra power would probably require making
first, middle, last seperate inputs, but then you come right back to the
"start, end, middle" verses "start, middle, end" ordering... :(

> > 2. Why are we restricting the output to strings?
>
> That _is_ a natural question, isn't it? :)
>
> > Couldn't the types of the 3 delimiter strings actually be
> > implicit template parameters?
> > (the char/wchar versions made me think of that)
>
> Yes, that is how it currently works;

Looks like I should read your code more thoroughly. I asked because I
didn't remember any conclusion like that in the list discussion. Sorry
about the stupid question :P


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