We know that std::deque::front()
return a reference to a first element of deque.
I would to know if this code is always safe:
//deque of lambdas
deque<function<void(void)>> funs;
// then is some other place:
// take a lock
m.lock();
auto f = move(funs.front()); // move the first lambda in f
funs.pop_front(); // remove the element from deque //now the value is hold by f
m_.unlock(); // unlock the resorce
f(); //execute f
I've tried this code using gcc-4.9 and works but I don't know if we can consider this code safe!