title: Map from int to type specifier
body: <p>I want to use a map to refer to a type specifier mainly to shorten my code from multiple uses of </p>
  
  <pre><code>std::unique_ptr&lt; Class &gt;(new class1);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>std::unique_ptr&lt; Class &gt;(new sampleMap[enum1]);
  </code></pre>
  
  <p>and then define my map so that it refers each enum value (<code>enum1</code>, <code>enum2</code>, ...) to my classes (<code>class1</code>, <code>class2</code>, ...).</p>
  
  <p>But I cannot define my map with the values being a type name like this</p>
  
  <pre><code>std::map &lt; int, Class &gt; mapName {
  {0, class1},
  {0, class1},
  ...
  };
  </code></pre>
  
  <p>since type name is not allowed in maps.</p>
  
  <p>The main reason I'm looking for an answer for this is to make my code more succinct by replacing a series of "<code>if</code>/<code>else if</code>" statements or "<code>switch</code>-case" statements into only one line of code where the output <code>std::unique_ptr&lt;Class&gt;(new class1);</code> is dynamically figured out through the map that I define. So, I just input the enum number and get the corresponding class instantiated for me. Otherwise, I would have to do this:</p>
  
  <pre><code>if (enum1 = 0)
  {
      std::unique_ptr&lt; Class &gt;(new class1);
  }
  else  if (enum2 = 0)
  {
      std::unique_ptr&lt; Class &gt;(new class2);
  }
  </code></pre>
  
  <p>(or a switch-case)
  But I want to do all above in one line like this:</p>
  
  <pre><code>std::unique_ptr&lt;Class&gt;(new sampleMap[enum1]);
  </code></pre>
  
  <p>plus the map declaration.</p>
  
  <p>Any clue how this could be done?</p>