You haven't specified a return value for apply
, I'll choose int
:
#include <string>
#include <type_traits>
template <class Function,
class = typename std::enable_if<
std::is_convertible<
decltype(std::declval<Function>()(std::declval<const unsigned int>())),std::string>::value>::type>
int apply(Function&& f);
Breaking it down: this ensures that a Function
:
std::declval<Function>()
called with a const unsigned int
parameter:
std::declval<Function()(std::declval<const unsigned int>())
has a return type:
decltype(std::declval<Function()(std::declval<const unsigned int>()))
that is convertible to std::string
:
std::is_convertible<decltype(std::declval<Function()(std::declval<const unsigned int>())), std::string>
whew.