Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>std::auto_ptr</code> and <code>std::unique_ptr</code> are incompatible in someways and a drop in replacement in others. So, no find/replace isn't good enough. However, after a find/replace working through the compile errors should fix everything except weird corner cases. Most of the compile errors will require adding a <code>std::move</code>.</p> <ul> <li><strong>Function scope variable:</strong><br> 100% compatible, as long as you don't pass it by value to another function.</li> <li><strong>Return type:</strong><br> not 100% compatible but 99% compatible doesn't seem wrong.</li> <li><strong>Function parameter by value:</strong><br> 100% compatible with one caveat, <code>unique_ptr</code>s must be passed through a <code>std::move</code> call. This one is simple as the compiler will complain if you don't get it right.</li> <li><strong>Function parameter by reference:</strong><br> 100% compatible.</li> <li><strong>Class member variable:</strong><br> This one is tricky. <code>std::auto_ptr</code>s copy semantics are evil. If the class disallows copying then <code>std::unique_ptr</code> is a drop in replacement. However, if you tried to give the class reasonable copy semantics, you'll need to change the <code>std::auto_ptr</code> handling code. This is simple as the compiler will complain if you don't get it right. If you allowed copying of a class with a <code>std::auto_ptr</code> member <em>without</em> any special code, then shame on you and good luck.</li> </ul> <p>In summary, <code>std::unique_ptr</code> is an unbroken <code>std::auto_ptr</code>. It disallows at compile time behaviors that were <em>often</em> errors when using a <code>std::auto_ptr</code>. So if you used <code>std::auto_ptr</code> with the care it needed, switching to <code>std::unique_ptr</code> should be simple. If you relied on <code>std::auto_ptr</code>'s odd behavior, then you need to refactor your code anyway.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload