Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Retrieves an element from the given associative container.
- *
- * This is a std::map::at() replacement for environments that do not provide it.
- * It fails an @a assert() check or throws an exception if the requested element
- * does not exist.
- */
- template<typename MapT>
- typename MapT::mapped_type const& const_at(typename MapT::key_type const& key, MapT const& map)
- {
- typename MapT::const_iterator it = map.find(key);
- if(it == map.end()) {
- assert(it != map.end());
- throw std::out_of_range("item_at()"); // Shouldn't get here without disabling assert()
- }
- return it->second;
- }
Advertisement
Add Comment
Please, Sign In to add comment