Check if returned std::function is "valid" in C++11
c++, c++11, task-queue
Solution
You can simply check `job` as a bool:
while (auto job = gen())
{
job();
}
That's a sort of shorthand which assigns `job` from `gen()` each time through the loop, stopping when `job` evaluates as false, relying on `std::function<>::operator bool`: http://en.cppreference.com/w/cpp/utility/functional/function/operator_bool
Problem
I want to implement a dynamic task queue like so: ``` typedef std::function<void(void)> Job; typedef std::function<Job(void)> JobGenerator; // .. JobGenerator gen = ...; auto job = gen(); while (IsValidFunction(job)) { job(); } ``` How can i implement `IsValidFunction`? Is there a sort of default value for `std::function` to check against?