|
Re: Lambda questions: msg#00305lib.boost.user
Jaakko Jarvi wrote: >> Is it possible to discern one-argument lambda expressions from >> two-argument expressions ? I would like to do something like this: > > Currently no. Can you tell a bit more where you would need this kind of > feature. It is possible to make this possible if there is real need. I am writing a set of formatting function for list output (or actually output of ranges of iterators). The signature of one of the functions is like this: format(begin, end, separator, function) The function can be used like this: cout << format(l.begin(), l.end(), ", ", 2 * _1) << endl; If 'l' is a list holding the values 1, 2, and 3 the output would be: 2, 4, 6 (the advantage when comparing to ostream_iterator is that format uses a separator while ostream_iterator uses a terminator) Now I would like to provide a variation of this function where the lamda function took two arguments: The element type of the list as before, and the ostream. That would make it possible to write: cout << format(l.begin(), l.end(), ", ", _2 << setw(4) << _1) << endl; (it becomes more relevant when the element type is eg. a double) I know I could just ditch the first version, but the primary aim of these functions is that they should be very easy to use (read: with minimum typing). And in the overwhelming majority of the cases one would use the first version. Secondly; the example is just a simplified example. Other versions of the function take more paramters like this: format(begin, end, prefix, separator, postfix) If it were possible to determine if an argument were a lambda expression one could write: format( l.begin(), l.end(), _1 << "(" << endl, _1 << "," << endl, _1 << endl << ")") to generate the following output: ( 1, 2, 3 ) Again; this is a simplified example - but you get the idea. The function are documented here: http://www.cc-consult.dk/prj/format2/html/index.html It is fully tested but the documentation and packaging is still needs some polish. It do not aim for inclusion in boost BTW - its just one of my pet projects that I'am using as a show-off for potential employers while looking for a job. -Claus ------------------------ Yahoo! Groups Sponsor ---------------------~--> Get 128 Bit SSL Encryption! http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/EbFolB/TM ---------------------------------------------------------------------~-> Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: Is intrusive_ptr the thing to use?: 00305, Hickman, Greg |
|---|---|
| Next by Date: | Using function_traits: 00305, Marshall Clow |
| Previous by Thread: | Re: Lambda questionsi: 00305, Jaakko Jarvi |
| Next by Thread: | matrix inside a matrix?: 00305, Stephen Crowley |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |