--- /dev/null
+#include <msp/debug/demangle.h>
+#include "maputils.h"
+
+using namespace std;
+
+namespace Msp {
+
+key_error::key_error(const type_info &t):
+ runtime_error(Debug::demangle(t.name()))
+{ }
+
+} // namespace Msp
--- /dev/null
+#ifndef MSP_CORE_MAPUTILS_H_
+#define MSP_CORE_MAPUTILS_H_
+
+#include <stdexcept>
+#include <typeinfo>
+
+namespace Msp {
+
+class key_error: public std::runtime_error
+{
+public:
+ key_error(const std::type_info &);
+};
+
+
+template<typename T>
+typename T::mapped_type &get_item(T &map, const typename T::key_type &key)
+{
+ typename T::iterator i = map.find(key);
+ if(i==map.end())
+ throw key_error(typeid(T));
+
+ return i->second;
+}
+
+template<typename T>
+const typename T::mapped_type &get_item(const T &map, const typename T::key_type &key)
+{
+ typename T::const_iterator i = map.find(key);
+ if(i==map.end())
+ throw key_error(typeid(T));
+
+ return i->second;
+}
+
+} // namespace Msp
+
+#endif