You will see the same number of copy operations if you change the code as follows:
int main()
{
A a;
auto&& lambda = [a]() -> int {
return a.value;
};
std::function<int()>{lambda};
}
The first copy / move construct occurs when creating a lambda. The second and third copy / move constructs occur during the construction of the std :: function. According to N3690, the std :: function constructor used is as follows:
template <class F> function(F);
, / . / .
(, ), /. , .
template <typename Arg> function(Arg&&);