any_cast with std::any's and std::optional
<p>If I put a <code>T</code> into an <code>std::any</code>, I can get it with <code>any_cast&lt;T&gt;(my_any)</code>. But does the standard (= C++17, in the ballot phase at the moment) include a function like <code>any_cast&lt;T&gt;(optional&lt;any&gt; oa)</code> which returns <code>nullopt</code> if oa is <code>nullopt</code> and <code>std::any_cast&lt;T&gt;(oa.value())</code> otherwise? Or something along those lines?</p>

<p><strong>Edit:</strong> Since people seem to be suggesting implementations, I'll also list what I use for now:</p>

<pre><code>/* using magic here to select between boost/std::experimental/std versions */

template&lt;typename T&gt;
inline const optional&lt;T&gt; any_cast(const optional&lt;any&gt;&amp; operand)
{
    return operand ? 
        optional&lt;T&gt;(any_cast&lt;T&gt;(operand.value())) :
        optional&lt;T&gt;(nullopt);
}
</code></pre>