Is there anyway to check if a generic lambda is callable with a specific type?!
#include <iostream>
#include <type_traits>
struct A { void DoAStuff() {} };
struct B { void DoBStuff() {} };
int main() {
auto fn = [](auto& arg) { arg.DoAStuff(); };
std::cout << std::boolalpha << std::is_invocable<decltype(fn), A&>::value << std::endl;
std::cout << std::boolalpha << std::is_invocable<decltype(fn), B&>::value << std::endl;
}
this code doesn't compile and I understand why. but I am wondering if there is anyway to get something like this to work? like we can define a class than when passed the lambda, return false instead of compilation error
error: no member named 'DoAStuff' in 'B'