I want to create a templated function which accepts and invokes a callable object(except pointer to data members) with arguments to pass to it. I want the template to only accept the following types:-
- Pointers to functions
- Pointers to member functions
- Lambda
- bind expressions
- std::function
- Functors
Like this...
template< class Function, class... Args >
explicit X( Function&& f, Args&&... args );
But the first argument is accepting any type and I want to create some validation such that it only accept callable objects and throw error(preferably in compile-time) if it invalidates.
There's a C++20 concept just for this purpose:
(Edited to add
is_member_object_pointer_v
due to comments below.)