title: noexcept visitation for std::variant
body: <p>For some standard library classes, access to parts of their contents may legitimately fail. Usually you have the choice between some potentially throwing method an one that is marked <code>noexcept</code>. The latter spares the check on the precondition, so if you want to take the responsibility yourself, you can. This can be used under circumstances where using exceptions are not permitted or when fixing a performance bottleneck.</p>
  
  <p>Example 1: <a href="https://en.cppreference.com/w/cpp/container/vector" rel="noreferrer"><code>std::vector</code></a> element access:</p>
  
  <pre><code>std::vector&lt;int&gt; vec;
  vec.at(n) // throws std::out_of_range
  vec[n] // potentially UB, thus your own responsibility
  </code></pre>
  
  <p>Example 2: <a href="https://en.cppreference.com/w/cpp/utility/optional" rel="noreferrer"><code>std::optional</code></a> access:</p>
  
  <pre><code>std::optional&lt;int&gt; optn;
  optn.value() // throws std::bad_optional_access
  *optn // potentially UB, thus your own responsibility
  </code></pre>
  
  <p>Now on to <a href="https://en.cppreference.com/w/cpp/utility/variant" rel="noreferrer"><code>std::variant</code></a>. Directly accessing an alternative somewhat follows this pattern:</p>
  
  <pre><code>std::variant&lt;std::string, int&gt; var;
  std::get&lt;int&gt;(var) // potentially throwing std::bad_variant_access
  *std::get_if&lt;int&gt;(&amp;var) // potentially UB, thus your own responsibility
  </code></pre>
  
  <p>But this time the signature changes, we have to inject <code>*</code> and <code>&amp;</code>. The downside of this is that we don't get automatic move semantics. One more thing to keep in your mind...</p>
  
  <p>But it gets worse if you have a look at <a href="https://en.cppreference.com/w/cpp/utility/variant/visit" rel="noreferrer"><code>std::visit(Visitor&amp;&amp; vis, Variants&amp;&amp;... vars)</code></a>. There is no <code>noexcept</code> alternative for it, although it only throws </p>
  
  <blockquote>
    <p>if any variant in vars is <a href="https://en.cppreference.com/w/cpp/utility/variant/valueless_by_exception" rel="noreferrer">valueless_by_exception</a>.</p>
  </blockquote>
  
  <p>This means for visiting variants you cannot choose to take the responsibility yourself, and if you have no choice and must avoid exceptions, you cannot visit <code>std::variants</code> at all with standard tooling! (apart from the terrible workaround of <code>switch</code>ing on <code>variant::index()</code>)</p>
  
  <p>To me, this looks like a pretty bad design oversight... or there a reason for this? And in case I'm right about the oversight, is there an initiative to fix this in the standard?</p>