c++ - Get object context from std::function -
i have std::function points class member function, eg, &foo:bar. std::function object record object context, eg, foo*? there way obtain context std::function object/class?
the purpose find out if unordered_multimap of functions contains function context (but not same class member function).
example;
std::unordered_multimap<int, std::function<int(int)>> callbacks; foo* myfoo = new foo(); callbacks[1].emplace( std::bind(&foo::bar, myfoo, std::placeholders::_1) ); callbacks[1].emplace( std::bind(&foo::bar2, myfoo, std::placeholders::_1) ); // callbacks contains 2 functions same object/context. want avoid // check context exists before inserting auto vcallbacks = callbacks.equal_range(1); (auto iter = vcallbacks.first; iter != vcallbacks.second; iter++) { std::function<int(int)> func = iter->second; // somehow check function object context myfoo if (func.??? == myfoo) // sorry cant add callback because object has registered 1 }
no, not. cannot inspect contents of std::function in useful way.
Comments
Post a Comment