template <typename Func> using function_ptr = add_pointer_t<Func>;
void foo(function_ptr<void (int)> callback);
typedef void function_ptr_t(int i); function_ptr_t* ptr;
#define INT_PTR int* INT_PTR p, q;
auto greet = std::mem_fn(&Foo::display_greeting);
Pairs nicely with std::bind, too, like so:
Foo foo; std::function<void(int)> setter = std::bind(&Foo::setValue, &foo, std::placeholders::_1); setter(42);
And std::function introduce some performance overhead.
Trivially solved with decltype, no need to remember anything.
decltype(std::mem_fn(&Foo::Whatever))
Typedef it if you want.
> And std::function introduce some performance overhead.
It's the same performance as a virtual function call. Pretty much the same as a function pointer invoke.
void foo(std::function<void(int)> callback);