samedi 8 février 2020

How to use move semantics when popping an object from a queue?

Please take a look at my code

class queue
{
        void pop(request & req)
        {
            mtx.lock();
            req = requests.front();
            requests.pop();
            mtx.unlock();
        }

    private:
        typedef std::queue<request> request_container;
        request_container requests;
        std::mutex mtx;
};

I am interested to use move semantics here req = requests.front(); Since I am going to pop the front object I don't further need it. Hence, it is a perfect case to move the front object into req. How would I do it?

Aucun commentaire:

Enregistrer un commentaire