shadowm

Untitled

Jun 30th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. /**
  2.  * Retrieves an element from the given associative container.
  3.  *
  4.  * This is a std::map::at() replacement for environments that do not provide it.
  5.  * It fails an @a assert() check or throws an exception if the requested element
  6.  * does not exist.
  7.  */
  8. template<typename MapT>
  9. typename MapT::mapped_type const& const_at(typename MapT::key_type const& key, MapT const& map)
  10. {
  11.     typename MapT::const_iterator it = map.find(key);
  12.     if(it == map.end()) {
  13.         assert(it != map.end());
  14.         throw std::out_of_range("item_at()"); // Shouldn't get here without disabling assert()
  15.     }
  16.     return it->second;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment