title: In C++, can I move something out of a std::variant?
body: <p>I have a resource-wrapper class which is noncopyable, but is movable. Something like this (pseudeocode)</p>
  
  <pre><code>class Wrapper {
    SomeResource* m_handle = nullptr;
  public:
    Wrapper(const Wrapper&amp;) = delete;
    Wrapper&amp; operator=(const Wrapper&amp;) = delete;
  
    Wrapper(SomeResource* handle) : m_handle(handle) { }
    Wrapper(Wrapper&amp;&amp; other) {
      std::swap(m_handle, other.m_handle);
    }
  }
  </code></pre>
  
  <p>This is all well and good, however I have a number of these, and I have a function which parses some data and returns EITHER a Wrapper or an alternative wrapper. I thought of using <code>std::variant</code> to express this in a return value. E.g.</p>
  
  <pre><code>std::variant&lt;Wrapper, AlternativeWrapper&gt; LoadData(void* bytes, size_t len)
  { ... }
  </code></pre>
  
  <p>I can write this function, and it all compiles. I.e. I construct a Wrapper inside the LoadData function, then I can move it into the variant which is then returned.</p>
  
  <p>But on the other side, when I want to get the value out, get this error (MSVC2019)</p>
  
  <pre><code>error C2280: 'Wrapper::Wrapper(const Wrapper&amp;)': attempting to reference a deleted function
  </code></pre>
  
  <p>My code looks like this.</p>
  
  <pre><code>auto result = LoadData(bytes, len);
  std::get&lt;Wrapper&gt;(result);
  </code></pre>
  
  <p>That makes sense as the result is still sticking around, but then how do I access it?</p>