std::invoke
takes something callable, and arguments to call it with, and does the call. std::invoke( f, args... )
is a slight generalization of typing f(args...)
that also handles a few additional cases.
Something callable includes a function pointer or reference, a member function pointer, an object with an operator()
, or a pointer to member data.
In the member cases, the first argument is interpreted as the this
. Then remaining arguments are passed to ()
(except in the pointer-to-member-data-case), with std::reference_wrapper
s unwrapping.
INVOKE was a concept in the C++ standard; C++17 simply exposed a std::invoke
which does it directly. I suspect it was exposed partly because it is useful when doing other metaprogramming, partly because every standard library has an implementation of INVOKE in it already and exposing it was basically free, and partly because it makes talking about INVOKE easier when it is a concrete thing.