title: Use data type (class type) as key in a map
body: <p>I have class <code>Base</code> and classes <code>Derived_1</code>, <code>Derived_2</code> ...
  I need derived classes to have an id. Those ids are used for further lookups etc, and thus need to be consecutive (no just some random numbers). Because derived classes are created by user, id can not be member of <code>Derived_N</code>. So I came up with <code>DerivedType</code> class.</p>
  
  <pre><code>class DerivedType
  {
      static unsigned id;
      unsigned m_id;
  public:
      DerivedType() : m_id(id++) {  }
  }
  </code></pre>
  
  <p>Now I want to create a mapping between <code>Derived_N</code> and <code>DerivedType</code>.
  Whenever <code>Derived_N</code> is created, this mapping looks if <code>DerivedType</code> for particular <code>Derived_N</code> already exist and returns it, otherwise create new and stores in the map.</p>
  
  <p>Actual question:
  Is there any way to use <code>std::map</code> with <strong>data type</strong> as <strong>key</strong> in the map?
  I am not afraid of any template-metaprogram solution.
  Or is there elegant way how to achieve my goal?</p>
  
  <p><strong>edit</strong> Date type -> Data type, I mean like ClassType, I am sorry :)</p>
  
  <p>I want to use it like:</p>
  
  <pre><code>Derived_5 d;
  DerivedType dt = getType(d); //Derived_5 is looked up in map, returning particular DerivedType
  dt.getId();
  </code></pre>
  
  <p>every instance of <code>Derived_N</code> (with same 'N') should have the same id throu DerivedType</p>
  
  <p><strong>EDIT2 - MY ANSWER</strong>
  I found better solution for my problem... It is like this:</p>
  
  <pre><code>atomic_counter s_nextEventClassID;
  
  typedef int cid_t;
  
  template&lt;class EventClass&gt;
  class EventClassID
  {
  public:
      static cid_t getID()
      {
          static cid_t classID = EventClassID::next();
          return classID;
      }
  
      static cid_t next() { return ++s_nextEventClassID; }
  };
  </code></pre>
  
  <p>since my question was how to use datatype in a map, I will mark some of yours answers, thank you</p>