Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between std::invoke and std::function? [closed]

Why do we need std::invoke, when we already have std::function? What is the difference between them? Both used to call callable objects. What's the point to add new template?

like image 999
Ivan Kush Avatar asked Jan 05 '23 09:01

Ivan Kush


1 Answers

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..

like image 158
Jesper Juhl Avatar answered Jan 14 '23 14:01

Jesper Juhl