title: How can I code something like a switch for std::variant?
body: <p>I have some <code>var = std::variant&lt;std::monostate, a, b, c&gt;</code> when <code>a, b, c</code> is some types.</p>
  <p>How, at runtime, do I check what type <code>var</code> contains?</p>
  <p>In the official documentation I found information that if <code>var</code> contains <code>a</code> type and I write <code>std::get&lt;b&gt;(var)</code> I get an exception. So I thought about this solution:</p>
  <pre><code>try {
    std::variant&lt;a&gt;(var);
    // Do something
  } catch(const std::bad_variant_access&amp;) {
    try {
      std::variant&lt;b&gt;(var);
      // Do something else
    } catch(const std::bad_variant_access&amp;) {
      try {
       std::variant&lt;c&gt;(var);
       // Another else
      } catch (const std::bad_variant_access&amp;) {
        // std::monostate
      }
    }
  }
  </code></pre>
  <p>But it's so complicated and ugly! Is there a simpler way to check what type <code>std::variant</code> contains?</p>