12345
template<typename MyCallback> void DoSomething(MyCallback callback) { callback(data, size); }
template<typename TData> void DoSomething(const std::function<void(TData,int)> &callback) { callback(data, size); }
1234567891011121314
#include <type_traits> #include <cstdint> // enable only if MYCALLBACK can be invoked with two arguments of type std::uint8_t* and std::size_t template < typename MYCALLBACK > typename std::enable_if< std::is_invocable< MYCALLBACK, std::uint8_t*, std::size_t >::value >::type DoSomething( MYCALLBACK callback ) { /* ... */ } int main() { DoSomething( []( const std::uint8_t* p, std::uintmax_t n ) { /* ... */ } ) ; // fine // DoSomething( []( int, int ) { /* ... */ } ) ; // *** error: no matching function }