dimanche 2 avril 2023

Impact of move semantic on data structure in C++

I am creating a stl deque as a class member of unique_ptr and inside one of the class member function returning this deque with move semantic. I am not sure what will be the state of class member deque after the return, either the content of deque becomes null or this deque itself becomes null. Does this cause the memory leak also?

code snippet.

class test
{
    deque<type> m_q;
    public:
    void qEvent(type t);
    type&& getQedEvent(deque<type> &q);
};
void test::qEvent(type t)
{
    m_q.emplace_back(move(t));
}
test::deque&& test::getQedEvent(deque<type>& q)
{
    return move(q);
}

Aucun commentaire:

Enregistrer un commentaire