Ivan Kush Ivan Kush - 1 year ago 157
C++ Question

What is the difference between std::invoke and std::function?

Why do we need

, when we already have
? What is the difference between them?

Answer Source

std::invoke is a generic way to activate any callable - a std::function, a pointer to function, a pointer to member function, a function object etc. Without having to know which one you are dealing with (and without having to use different syntax). It's mostly useful in generic programming (templates).

A standard function on the other hand is a generic container for a callable "thing". Not at all the same..

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download