#ifndef TYPEMAP_H #define TYPEMAP_H #include #include template class TypeMap { typedef std::unordered_map InternalMap; public: typedef typename InternalMap::iterator iterator; typedef typename InternalMap::const_iterator const_iterator; typedef typename InternalMap::value_type value_type; const_iterator begin() const { return m_map.begin(); } const_iterator end() const { return m_map.end(); } iterator begin() { return m_map.begin(); } iterator end() { return m_map.end(); } // finds the value associated with type "Key" in the typemap template iterator find() { return m_map.find(getTypeId()); } template const_iterator find() const { return m_map.find(getTypeId()); } template bool contains() { return m_map.count(getTypeId()); } // associates a value with the type "Key" template void put(ValueType &&value){ m_map[getTypeId()] = std::forward(value); } template void remove() { m_map.erase(getTypeId()); } private: template inline static int getTypeId(){ static const int id = LastTypeId++; return id; } static std::atomic_int LastTypeId; InternalMap m_map; }; template std::atomic_int TypeMap::LastTypeId(0); #endif // TYPEMAP_H