//====================================================================== // ConstSubscriptMap.hh // // This template provides a variation of std::map with const // subscripting operator. It aborts the program in case the key // can not be found. // // I. Volobouev // 03/12/2001 //====================================================================== #ifndef CONSTSUBSCRIPTMAP_HH #define CONSTSUBSCRIPTMAP_HH #include #include #include template , class Allocator = std::allocator > > class ConstSubscriptMap : public std::map { public: inline const T& operator[](const Key&) const; }; template const T& ConstSubscriptMap:: operator[](const Key& key) const { typename ConstSubscriptMap::const_iterator it = find(key); if (it == std::map::end()) { std::cerr << "ConstSubscriptMap: key \"" << key << "\" not found." << "\nAborting." << std::endl; abort(); } return it->second; } #endif // CONSTSUBSCRIPTMAP_HH