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:-
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:
template<class Function, class... Args>
requires std::invocable<Function, Args...>
void X(Function&& f, Args&&... args);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.