This should work -- we should have unit tests for this.
#include <functional>
#include <iostream>
struct Foo
{
Foo(int num) : num_(num) {}
void print_add(int i) const { std::cout << num_ + i << '\n'; }
int num_;
};
int main()
{
// store a call to a member function
std::copyable_function<void(const Foo&, int)> f_add_display = &Foo::print_add;
const Foo foo(314159);
f_add_display(foo, 1);
f_add_display(314159, 1);
}
This should work -- we should have unit tests for this.
https://godbolt.org/z/dfEfeWWe4