Using lambda as an argument: std :: function or template?

I am learning C ++ 11, especially interested in lambda.

After some practice, I suggested that lambda closure is an unnamed functional entity.

So, I wrote this code.

template <class callable_object>
void lambda_caller( callable_object lambda )
{
    std::cout<< sizeof(lambda) << endl;
    lambda();
}

I know that instead of using a template I can use std::function, but I don't want the overhead of casting.

But I found one problem while reading this question: Why can't I create a lambda vector in C ++ 11?

The defendant said: “Each lambda has a different type, even if they have the same signature.”

Compilers make different codes for different classes.

So I think my compiler will make a different version lambda_callerwhenever I make a different definition of lambda to pass.

, std::function? -?

+5
2

. Lambda - ()(), . - .

+5

std::function - . , . , , , , 3 ​​ , , 4. std::function , , ( ).

, , , . std::tuple. . , ++ - , Boost.Fusion .

0

All Articles