title: Should use unique_ptr to more easily implement "move" semantics?
body: <p><strong>Edit:</strong> made <code>Foo</code> and <code>Bar</code> a little less trivial, and direct replacement with <code>shared_ptr&lt;&gt;</code> more difficult.</p>
  
  <hr>
  
  <p>Should <code>unique_ptr&lt;&gt;</code> be used as an easier way to implement move semantics?</p>
  
  <p>For a class like</p>
  
  <pre><code>class Foo
  {
      int* m_pInts;
      bool usedNew;
      // other members ...
  
  public:
      Foo(size_t num, bool useNew=true) : usedNew(useNew) {
          if (usedNew)
              m_pInts = new int[num];
          else
              m_pInts = static_cast&lt;int*&gt;(calloc(num, sizeof(int)));
      }
      ~Foo() {
          if (usedNew)
              delete[] m_pInts;
          else
              free(m_pInts);
      }
  
      // no copy, but move
      Foo(const Foo&amp;) = delete;
      Foo&amp; operator=(const Foo&amp;) = delete;
      Foo(Foo&amp;&amp; other) {
          *this = std::move(other);
      }
      Foo&amp; operator=(Foo&amp;&amp; other) {
          m_pInts = other.m_pInts;
          other.m_pInts = nullptr;
          usedNew = other.usedNew;
          return *this;
      }
  };
  </code></pre>
  
  <p>Implementing move becomes more tedious as data members are added.  However, the moveable data can be placed in a separate <code>struct</code>, an instance of which is managed by <code>unique_ptr&lt;&gt;</code>.  This allows <code>=default</code> to be used for move:</p>
  
  <pre><code>class Bar
  {
      struct Data
      {
          int* m_pInts;
          bool usedNew;
          // other members ...
      };
      std::unique_ptr&lt;Data&gt; m_pData = std::make_unique&lt;Data&gt;();
  
  public:
      Bar(size_t num, bool useNew = true) {
          m_pData-&gt;usedNew = useNew;
          if (m_pData-&gt;usedNew)
              m_pData-&gt;usedNew = new int[num];
          else
              m_pData-&gt;m_pInts = static_cast&lt;int*&gt;(calloc(num, sizeof(int)));
      }
      ~Bar() {
          if (m_pData-&gt;usedNew)
              delete[] m_pData-&gt;m_pInts;
          else
              free(m_pData-&gt;m_pInts);
      }
  
      // no copy, but move
      Bar(const Bar&amp;) = delete;
      Bar&amp; operator=(const Bar&amp;) = delete;
      Bar(Bar&amp;&amp; other) = default;
      Bar&amp; operator=(Bar&amp;&amp; other) = default;
  };
  </code></pre>
  
  <p>Other than the memory for the <code>unique_ptr&lt;&gt;</code> instance always being on the heap, what other problems exist with an implementation like this?</p>