I am wondering if there is a way to check if the function pointer assigned to you in std::function , nullptr . I expected that ! -operator will do this, but it only works when something like nullptr_t assigned to the function.
typedef int (* initModuleProc)(int); initModuleProc pProc = nullptr; std::function<int (int)> m_pInit; m_pInit = pProc; std::cout << !pProc << std::endl;
I wrote this helper function to get around this now.
template<typename T> void AssignToFunction(std::function<T> &func, T* value) { if (value == nullptr) { func = nullptr; } else { func = value; } }
source share