|
Boost : |
From: Asger Alstrup Nielsen (alstrup_at_[hidden])
Date: 2002-03-25 08:13:18
> [3]
>
> std::find_if(v.begin(), v.end(), _1 > 5);
>
> Which one do you prefer?
I prefer 3.
This is not relevant to my critique. Please read what I have written
once more, and point out what is not clear.
It might help to illustrate one of my points by writing the following as
an anonymous lambda expression:
int foo(int i) {
switch (i) {
case 0: return i + 1;
case 1:
try {
return bar(i + 3);
} catch(...) {
return -1;
}
default:
if (i < 10) {
return i;
} else {
int j = i;
while (i > 100) {
j += i;
i /= 2;
}
return j;
}
}
}
My initial try to write this with LL is this:
int j;
std::for_each(v.begin(), v.end(),
switch_statement(_1,
case_statement<0>(_1 + 1),
case_statement<1>(try_catch(
bar(_1 + 3),
catch_all(-1)
)
),
default_statement(if_then_else(_1 < 10,
1,
( j = 1,
while_statement(_1 <
100,
(j += _1,
i /= 2
)
),
j)
)
)
);
);
I can't check it because I'm stuck with VC6, but there is at least one
error in the above. Can you spot it?
I do not think this style of programming is something to encourage.
I much prefer the basic lambda library with only basic expression
support, assignment, scoping and boost::function interaction.
Greets,
Asger Alstrup Nielsen
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk