test std::function validity after bind to member function
问题 For the struct: struct A { int var = 10; void check() { std::cout << "var is " << var << std::endl; } }; Say I create a std::function object of A::check() , using a dynamically allocated a object: auto a_ptr = std::make_unique<A>(); std::function<void()> f = std::bind(&A::check, a_ptr.get()); //...later/elsewhere... f(); It would be nice for safety if I could test f to see if the bound A object is still alive. Is it possible to retrieve that information from f directly? Assume a_ptr is not