lundi 27 novembre 2017

How to define a lambda expression without both std::function and auto?

I have read the item31 of "Effective Modern C++" and web page of http://ift.tt/OEhZWO and wonder if I can define a lambda by its definite type instead of the wrapped type of std::function or keyword of auto and how can I accomplish that.

for instance, for the type int:

auto x_1 = 5; // type deduction
int x_2 = 5;  // defined by definite type
// both x_1, x_2 are int variables of value 5

now, when the problem comes to the lambda:

auto f_1_0 = []()->int{return 5;};
std::function<int(void)> f_1_1 = []()->int{return 5;};
SomeType f_2 = []()->int{return 5;}; // what's the SomeType here?

Aucun commentaire:

Enregistrer un commentaire