title: How to filter out elements of certain data types in a vector of std::variant?
body: <p>I have a <code>std::vector</code> of <code>std::variant</code> elements with type <code>int</code> or <code>std::set&lt;int&gt;</code>. I want to loop over this vector and <code>insert</code> an extra item if the iterated element is of type <code>std::set&lt;int&gt;</code>. However, it seems that querying the index at run-time is not allowed. How can I achieve this?</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;variant&gt;
  #include &lt;set&gt;
  #include &lt;vector&gt;
  
  int main()
  {
      using Variants = std::variant&lt;int, std::set&lt;int&gt;&gt;;
  
      std::vector&lt;Variants&gt; var_vec;
      var_vec.push_back(999);
      std::set&lt;int&gt; a = {0,1,2};
      var_vec.push_back(a);
  
      for (int i = 0; i &lt; var_vec.size(); ++i)
      {
          // if the element var_vec[i] is of type std::set&lt;int&gt;
          if (var_vec[i].index() == 1) var_vec[i].insert(888);   // !ERROR! How to achieve this?
      }
      
      return 0;
  }
  </code></pre>
  <p>Error message:</p>
  <pre><code>error: '__gnu_cxx::__alloc_traits&lt;std::allocator&lt;std::variant&lt;int, std::set&lt;int, std::less&lt;int&gt;, std::allocator&lt;int&gt; &gt; &gt; &gt;, std::variant&lt;int, std::set&lt;int, std::less&lt;int&gt;, std::allocator&lt;int&gt; &gt; &gt; &gt;::value_type' {aka 'class std::variant&lt;int, std::set&lt;int, std::less&lt;int&gt;, std::allocator&lt;int&gt; &gt; &gt;'} has no member named 'insert'
  </code></pre>