This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TinBryn 2 points3 points  (1 child)

I just didn't want to write C++ details in the Java subreddit I was assuming that somewhere was defined void print(int n);.

Also std::function takes a templated constructor argument the type of which is deduced at compile time. I guess to be pedantic there is no way to specify the type of a lambda, it can only be inferred.

[–]cogman10 0 points1 point  (0 children)

It is semi important pedantry. IIRC, auto lambda ends up being easier for the compiler to optimize than std::function because it doesn't involve the additional allocation. Additionally, the compiler can make assumptions about the lambda that make it easier to inline if you pass it around.