title: How to access compatible std::variant variants?
body: <pre><code>#include &lt;variant&gt;
  
  
  struct A
  {
      void foo(){}
  };
  
  
  struct B
  {
      void foo(){}
  };
  
  int main()
  {
      std::variant&lt; A, B &gt; v{ A{} };
      v.foo();  // doesn't work
  }
  </code></pre>
  <p>How do I use the <code>std::variant</code> value not knowing it's type but knowing it's properties? I believe this is called Generic Polymorphism equivalent to Duck Typing.</p>