title: Trouble with storing a type tag when implementing an std::variant-like class
body: <p>My aim is to write <code>std::variant</code>, may be not full blown, but at least with fully working constructor/destructor pair and <code>std::get&lt;&gt;()</code> function.</p>
  
  <p>I tried to reserve a memory using char array. The size of it is determined by the biggest type, which is found by using <code>find_biggest_size&lt;&gt;()</code> function. The constructor uses static assert, because it performs check if the type is in the list of specified types. For now, the constructor and in place constructor works.</p>
  
  <pre><code>template &lt;typename ... alternatives&gt;
  class variant
  {
      char object[find_biggest_size&lt;alternatives...&gt;::value];
  public:
      template &lt;typename T&gt;
      variant(T&amp;&amp; other)
      {
          static_assert(is_present&lt;T, alternatives...&gt;::value, "type is not in range");
          new ((T*)&amp;object[0]) T(std::forward&lt;T&gt;(other));
      }
  
      template &lt;typename T, typename ... ArgTypes&gt;
      variant(in_place_t&lt;T&gt;, ArgTypes&amp;&amp; ... args)
      {
          static_assert(is_present&lt;T, alternatives...&gt;::value, "type is not in range");
          new ((T*)&amp;object[0]) T(std::forward&lt;ArgTypes&gt;(args)...);
      }
  
      ~variant()
      {
          // what to do here?
      }
  };
  </code></pre>
  
  <p>Then I've stumbled upon a problem. I don't know what destructor to execute when the object dies. On top of that, it is impossible to access the underlying object, since I can't specialize <code>std::get&lt;&gt;()</code> to get the right type. </p>
  
  <p>My question is: how to store the type after the creation of the object? Is it the right approach? If not, what should I use?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I tried to apply the comments. The problem is that the index of the type that is currently alive can't be <code>constexpr</code>, thus I can't extract the needed type from type list and invoke appropriate destructor.</p>
  
  <pre><code>~variant()
  {
      using T = typename extract&lt;index, alternatives...&gt;::type;
      (T*)&amp;object[0]-&gt;~T();
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I've made a baseline implementation. It works, but has lots of missing features. You can find it <a href="https://codereview.stackexchange.com/questions/141004/custom-basic-stdvariant">here</a>. I would be glad to receive a review, but please first read <a href="https://codereview.stackexchange.com/help/how-to-answer">how do I write a good answer?</a>. </p>