Move semantics using LValue reference

So, the semantics of Move are great, giving us better performance.

I read that it was a completely new feature, and without C ++ 11 it is impossible to do.

But can we do this before C ++ 11? Like something that looks like below.

class AAA
{
private:
    int* m_data;
public:
    AAA(int _data) : m_data(new int(_data)) { }
    AAA(AAA& _other) // Not using RValue reference.
    {
        m_data = _other.m_data;
        _other.m_data = nullptr;
    }

    ~AAA() { delete m_data; }
};

int main()
{
    AAA sth1(100);
    AAA sth2(sth1)
    return 0;
}

I thought that for the existence of an RValue reference, this is not the execution of the same functions whose argument is just slightly different (e.g. Const and Non-Const).

Just by using the RValue reference, which is just another “type”, we can simultaneously execute both the Copy constructor and the Move constructor. What is it.

I wonder if I'm right or something huge.

Thanks in advance.

+3
source share
4 answers

std::auto_ptr , . , . Rvalue , .

rvalue / (, ), lvalue ( ), , .

+3

, move , (Boost.Move) ++ 03 (, ). , , , , , .

+3

, - , lvalues, const. const lvalues ​​ , .

0

, rvalue ? ctor , const const. rvalue rvalue ctor , rvalues ​​ .

0

All Articles