mardi 27 mars 2018

How to pass and share shared_ptr ownership with a better performance?

For example

class A
{
public:
    // Option 1
    void setI_1(shared_ptr<int> i) { m_i = i; }

    // Option 2
    void setI_2(shared_ptr<int> i) { m_i = move(i); }

    // Option 3
    void setI_3(shared_ptr<int> const& i) { m_i = i; }

private:
    shared_ptr<int> m_i;        
};

Usually which option is better?

Aucun commentaire:

Enregistrer un commentaire