1234567891011121314
#include <functional> #include <cstring> template < typename R, typename A > using my_unary_function = std::function< R(A) > ; int main() { my_unary_function< std::size_t, const char* > fn = &std::strlen ; fn = [] ( const char* cstr ) { return cstr ? std::strlen(cstr) : 0 ; } ; // note: members result_type and argument_type are deprecated (and removed in C++20) static_assert( std::is_same_v< std::size_t, decltype(fn)::result_type > ) ; static_assert( std::is_same_v< const char*, decltype(fn)::argument_type > ) ; }