title: Access class implementation instanciated from template parameter packs
body: <p>I would like to instantiate all <code>States</code> in the <code>MachineT</code> as a <code>shared_ptr&lt;T&gt;</code> then access them by typename.</p>
  
  <p>In the following code, it refers to the instantiation (MachineT constructor) and a way to access the states (get function).</p>
  
  <p>Is there any hashmap trick or a way to store in the class an "Index" information such as <code>StateA::Index</code>?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;memory&gt;
  #include &lt;vector&gt;
  
  template &lt;typename... States&gt;
  class MachineT {
   public:
    MachineT() {
      states_.resize(sizeof...(States));
      for (unsigned i = 0; i &lt; states_.size(); ++i) {
        // Instanciate states
        // states_[i].reset(new decltype(State[i])());
      }
    }
    ~MachineT() {}
  
    class State {
      State(int state_id) : state_id_(state_id) {}
      const size_t state_id_;
    };
  
    template&lt;typename T&gt;
    std::shared_ptr&lt;T&gt; get() {
      // Retrun the shared_ptr to the State
    }
  
    std::vector&lt;std::shared_ptr&lt;State&gt;&gt; states_;
  };
  
  struct StateA;  // Forward declaration
  struct StateB;
  using StateMachine = MachineT&lt;StateA, StateB&gt;;
  
  class StateA : StateMachine::State {};
  class StateB : StateMachine::State {};
  
  int main(int argc, char const* argv[]) {
    StateMachine sm;
  
    std::shared_ptr&lt;StateA&gt; state_a = sm.get&lt;StateA&gt;();
    return 0;
  }
  </code></pre>