Should std :: auto_ptr <> :: operator = reset / free an existing pointee?

I read here about std :: auto_ptr <> :: operator =

Note, however, that the left side of the object is not automatically freed when it already points to some object. You can explicitly do this by calling the reset member function before assigning it a new value.

However, when I read the source code for the header file C:\Program Files\Microsoft Visual Studio 8\VC\ce\include\memory

template<class _Other>
    auto_ptr<_Ty>& operator=(auto_ptr<_Other>& _Right) _THROW0()
    { // assign compatible _Right (assume pointer)
    reset(_Right.release());
    return (*this);
    }

auto_ptr<_Ty>& operator=(auto_ptr<_Ty>& _Right) _THROW0()
    { // assign compatible _Right (assume pointer)
    reset(_Right.release());
    return (*this);
    }

auto_ptr<_Ty>& operator=(auto_ptr_ref<_Ty> _Right) _THROW0()
    { // assign compatible _Right._Ref (assume pointer)
    _Ty **_Pptr = (_Ty **)_Right._Ref;
    _Ty *_Ptr = *_Pptr;
    *_Pptr = 0; // release old
    reset(_Ptr); // set new
    return (*this);
    }

What is the correct / standard behavior? How do other STL implementations behave? If the above site has incorrect / outdated information, which website do you recommend as a link?

+3
1

auto_ptr , .

2003 (§20.4.5.1):

auto_ptr& operator=(auto_ptr& a) throw();

7 : delete get() .

8 : reset(a.release()).

9 : *this.

, auto_ptr , reset , auto_ptr.

, , .

+6

Source: https://habr.com/ru/post/1739805/


All Articles