title: Which STD container to use to get [] operator and erase elements without moving memory around?
body: <p>I used <code>std::vector&lt;MyClass&gt;</code> and everything was fine until I had to use <code>erase()</code> function. Problem caused by <code>MyClass</code> having</p>
  <pre><code>MyClass(const MyClass&amp;) = delete;
  MyClass&amp; operator=(const MyClass&amp;) = delete;
  </code></pre>
  <p>This is needed because <code>MyClass</code> holds <code>unique_ptr</code> objects and I generally want to avoid copy. But at this point my code has index access [] operator utilized, and I dont want to re write chucks of code. Is there a container in STD that is suitable?</p>
  <p>Edit:</p>
  <p>To people suggesting usage of move constructor, I've tried this:</p>
  <pre><code>//MyClass(const MyClass&amp;) = delete;
  //MyClass&amp; operator=(const MyClass&amp;) = delete;
  MyClass(MyClass&amp;&amp;) = default;
  </code></pre>
  <p>but compiler(g++) still gives error:</p>
  <pre><code>/usr/include/c++/11/bits/stl_algobase.h:405:25: error: use of deleted function ‘M::MyClass&amp; M::MyClass::operator=(const M::MyClass&amp;)’
    405 |               *__result = std::move(*__first);
        |               ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
  </code></pre>
  <p>saying:</p>
  <pre><code>note: ‘M::MyClass&amp; M::MyClass::operator=(const M::MyClass&amp;)’ is implicitly declared as deleted because ‘M::MyClass’ declares a move constructor or move assignment operator
  </code></pre>
  <p>or I should not use <code>default</code> keyword and actually define move constructor?</p>