|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2008-03-30 17:28:32
on Fri Mar 28 2008, Steven Watanabe <watanabesj-AT-gmail.com> wrote:
> AMDG
>
> Giovanni Piero Deretta wrote:
>> That is, something like this is actually possible:
>>
>> void foo () {
>> int i =
>> lambda
>> // introduce formal parameter names
>> [ _<class left>(),
>> _<class right>()
>> ]
>> // now use them!
>> [_<left>() + _<right>()]
>> // actual parameters values
>> ( 10, 20 );
>> }
>>
>> The _<...>() looks a bit clumsy, but it might be actually usable.
>>
>
> I'd rather not use _. arg sound better.
> lambda<class left, class right>(arg<left>() + arg<right>())
lambda<args(class left, class right)>(arg<left>() + arg<right>())
I actually like the short nondescriptive names. It's very rare that the
semantic information in a descriptive name is more valuable than the
syntactic economy of the existing syntax. Just compare the above to:
_1 + _2.
Which do you find clearer? When the lambda expression is complicated
enough that having real names is actually a win, I am usually inclined
to write a separate, named function (object), anyway.
> Wow. This is awesome. You'd probably better reference the standard
> (3.3.1/5) since most people will look at this and be surprised to find
> that it's legal. (I certainly was)
Not so fast. It's legal outside a function, but inside a function
"class A"
refers to a local class of the function, which isn't a legal template
parameter. You might try the following at
http://www.comeaucomputing.com/tryitout/
template <class T>
struct x{};
template <class T>
void f()
{
x<class A> y;
}
-- Dave Abrahams Boost Consulting http://boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk