7 // https://en.cppreference.com/w/cpp/utility/functional/bind
8 // Ep 15: https://www.youtube.com/watch?v=JtUZmkvroKg & https://www.youtube.com/watch?v=ZlHi8txU4aQ
13 void print(T i
, const string
& s
)
15 cout
<< i
<< ' ' << s
<< endl
;
22 // The given function must be a concrete one (the generic parameter of 'print' must be specified in this case).
23 // 'ref' is to create a standard reference to 'i'.
24 // the second parameter create a parameter in the new created function.
25 // 'bind' were originaly from the Boost library.
26 const auto f
= bind(&print
<int>, ref(i
), placeholders::_1
);
33 function
<void(const string
&)> f2(f
); // Create a 'std::function'.
38 // Prefer lambdas instead of bind.
41 // Swapping arguments.
42 const auto f
= [](auto&& arg1
, auto&& arg2
)
44 // Perfect forwarding (not necessary).
45 print(forward
<decltype(arg2
)>(arg2
), forward
<decltype(arg1
)>(arg1
));
55 cout
<< "-----" << endl
;