Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:33:50+00:00 2026-06-15T19:33:50+00:00

For std::unique_ptr s p1 and p2 , what are differences between std::move() and std::unique_ptr::reset()

  • 0

For std::unique_ptrs p1 and p2, what are differences between std::move() and std::unique_ptr::reset()?

p1 = std::move(p2);

p1.reset(p2.release());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:33:52+00:00Added an answer on June 15, 2026 at 7:33 pm

    The answer should be obvious from the standard’s specification of move assignment in [unique.ptr.single.assign]/2:

    Effects: Transfers ownership from u to *this as if by calling reset(u.release()) followed by an assignment from std::forward<D>(u.get_deleter()).

    Clearly move assignment is not the same as reset(u.release()) because it does something additional.

    The additional effect is important, without it you can get undefined behaviour with custom deleters:

    #include <cstdlib>
    #include <memory>
    
    struct deleter
    {
      bool use_free;
      template<typename T>
        void operator()(T* p) const
        {
          if (use_free)
          {
            p->~T();
            std::free(p);
          }
          else
            delete p;
        }
    };
    
    int main()
    {
      std::unique_ptr<int, deleter> p1((int*)std::malloc(sizeof(int)), deleter{true});
      std::unique_ptr<int, deleter> p2;
      std::unique_ptr<int, deleter> p3;
    
      p2 = std::move(p1);  // OK
    
      p3.reset(p2.release());  // UNDEFINED BEHAVIOUR!
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the sole difference between boost::scoped_ptr<T> and std::unique_ptr<T> the fact that std::unique_ptr<T> has move
I am using std::unique_ptr in this piece of code which compiles and runs as
I'm using the pimpl-idiom with std::unique_ptr : class window { window(const rectangle& rect); private:
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>
for( int i = 0; i < lines; i++ ) { std::unique_ptr<BYTE[]> pLine( new
This is a code that uses unique_ptr: struct Foo{ Foo(){std::cout << Ctor called\n;} ~Foo(){std::cout
std::unique_ptr<int> ptr; ptr = new int[3]; // error error C2679: binary '=' : no
I have a class containing a std::unique_ptr<> and I want to put instances of
Is there some equivalent class for C++1x's std::unique_ptr in the boost libraries? The behavior
What is wrong with this program? #include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.