[Cs3] bind, lambda and function pointers
Mikhail Nesterenko
mikhail at cs.kent.edu
Fri Feb 26 16:51:38 EST 2016
CS3 students,
It turns out that std::bind and (in general) lambda definition do not
produce function pointers. Even though a lambda without captured
variables may be represented as a function pointer. What bind/lambda
produce is implementation dependent. And having "auto" as a type is a
good way of referring to the return value of bind and lambda definition.
For example:
auto newf = bind (myfunc, _1, _2);
However, C++11 has a mechanism of treating function
pointers/functors/bind results/lambdas with the same signatures
similarly. It is called std::function and is defined in <functional>
header file.
I came up with an example:
http://vega.cs.kent.edu/~mikhail/classes/cs3/Examples/STLAlgorithms/Functors/function.cpp
Where I set up a vector of point-able objects that are then treated uniformly.
Please take a look,
--
Mikhail
More information about the cs3
mailing list