title: Insert into unordered_map hanging on runtime
body: <p>I've run into an issue that I can only describe as completely unfamiliar to me, and I could use some help. For context, I don't know a whole lot about c++ programming and am trying to learn more, so the code I'm currently working on is more educational than anything else. I want to create an <code>unordered_map</code> that contains a string as a key and a vector as the key's associated value. Traditionally, this would be trivial. However, my program is trying to parse json data into this <code>unordered_map</code> data structure and there are no guarantees on the type of each vector being known in advance. The only thing that I can guarantee is that the type of each vector will be a one of the types in the following set of types: <code>string, int, double</code>. In order to try and achieve an unordered_map that functions this way, I've tried to use <code>variant</code>, but currently the variant implementation is leading to a timeout error. I'm hoping to get some advice on the cause of the timeout, and, ideally, how to resolve it.</p>
  <p>The code is as follows (minimum example that replicates this issue):</p>
  <pre><code>
  #include &lt;nlohmann/json.hpp&gt;
  #include &lt;unordered_map&gt;
  #include &lt;variant&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt; 
  
  using json = nlohmann::json;
  
  int main() {
  // map stores col name as string and vector with col type
      std::unordered_map&lt;std::string, std::vector&lt;std::variant&lt;double, long, std::string&gt;&gt;&gt; mp;
  
     // input is type nlohmann::json
     json input = &quot;{ \&quot;happy\&quot;: \&quot;yes\&quot;, \&quot;pi\&quot;: 3.141, \&quot;t\&quot;: 1608008400000 }&quot;_json;
  
     for(auto&amp; el : input.items()) { 
         if (mp.find(el.key()) == mp.end()) {
             std::cout &lt;&lt; &quot;trying insertion for key &quot; &lt;&lt; el.key() &lt;&lt; std::endl;
             mp.insert({ el.key(), std::vector&lt;std::variant&lt;double, long, std::string&gt;&gt;{ el.value() } });
             std::cout &lt;&lt; &quot;inserted &quot; &lt;&lt; el.key() &lt;&lt; &quot; successfully!&quot; &lt;&lt; std::endl;
         }
      }
      return 0;
  }
  </code></pre>
  <p>Here is my input (note that my input is being passed to this program as type nlohmann::json):
  <code>{&quot;c&quot;:127.88,&quot;h&quot;:127.9,&quot;l&quot;:124.13,&quot;n&quot;:867462,&quot;o&quot;:124.34,&quot;t&quot;:1608008400000,&quot;v&quot;:157572262.0,&quot;vw&quot;:126.5535},{&quot;c&quot;:127.81,&quot;h&quot;:128.37,&quot;l&quot;:126.56,&quot;n&quot;:550012,&quot;o&quot;:127.41,&quot;t&quot;:1608094800000,&quot;v&quot;:95913591.0,&quot;vw&quot;:127.5459}</code></p>
  <p>And here is the current output:</p>
  <p><img src="https://i.stack.imgur.com/NL1uk.png" alt="And here is the current output" /></p>
  <pre><code>inserted c successfully!
  trying insertion for key h
  inserted h successfully!
  trying insertion for key l
  inserted l successfully!
  trying insertion for key n
  inserted n successfully!
  trying insertion for key o
  inserted o successfully!
  trying insertion for key t
  [1]    40305 killed     ./test
  </code></pre>
  <p>I have tried to address a bunch of potential different issues regarding why this could be happening, but I have essentially confirmed via trial and error that the issue occurs when I try and use the <code>std::variant&lt;std::string, long, double&gt;</code> for my vector type. When I assign all of the vectors a uniform type (<code>double</code>, for example), all insertions work perfectly. However, the issue is one of extensibility. Even though this example only contains doubles and longs, in the future I'd ideally like to be able to parse some data that looks like this:
  <code>{&quot;a&quot;: &quot;test&quot;, &quot;b&quot;: 1243.343, &quot;c&quot;: 120910394023332} </code>
  without error and have the return values be (with types shown for clarity):</p>
  <p><code>a : vector&lt;string&gt;{&quot;test&quot;}, b : vector&lt;double&gt;{1243.343}, c : vector&lt;long&gt;{120910394023332}</code></p>
  <p>If there's anything that I can clarify that would help answer this, please just let me know and I'll add it in.</p>