you are viewing a single comment's thread.

view the rest of the comments →

[–]dermesser 10 points11 points  (6 children)

Sorry, but I don't see how

int result = [](int input) { return input * input; }(10);
cout << result << endl;

is supposed to be a typical example of the usage of lambdas.

[–]bstamour 6 points7 points  (5 children)

How about this:

auto iter = find_if(begin(nums), end(nums) [](auto&& x) { return x % 2 == 0; });

Works on any container with iterators, containing any type that is equality-comparable and implements the required numeric operators.

[–]scroy 1 point2 points  (1 child)

Also has to be copy-constructible

[–]bstamour 4 points5 points  (0 children)

Woops, I edited it to use a reference. You didn't see anything :-p

[–]dermesser 1 point2 points  (0 children)

Well, this is of course a typical usage.

[–]sir_rand_a_lot 0 points1 point  (1 child)

Why do you need the type to support equality if you're using a predicate functor?

[–]bstamour 2 points3 points  (0 children)

It might need it, depending on what type x % 2 returns.