6 #include <boost/optional.hpp>
9 template<
class Key,
class T,
class Compare=std::less<Key>,
class Alloc=std::allocator<std::pair<const Key, T> > >
10 class Map:
public std::map<Key, T, Compare, Alloc> {
12 typedef std::map<Key, T, Compare, Alloc> map_type;
14 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
16 friend class boost::serialization::access;
19 void serialize(S &s,
const unsigned ) {
20 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(map_type);
28 explicit Map(
const Compare& comp,
const Alloc& alloc = Alloc())
29 : map_type(comp, alloc) {}
31 template <
class InputIterator>
32 Map(InputIterator first, InputIterator last,
const Compare& comp = Compare(),
const Alloc& alloc = Alloc())
33 : map_type(first, last, comp, alloc) {};
49 boost::optional<T>
get(
const Key &key)
const {
50 typename map_type::const_iterator found = this->find(key);
51 return found==this->end() ? boost::optional<T>() : boost::optional<T>(found->second);
59 typename map_type::const_iterator found = this->find(key);
60 if (found==this->end())
61 throw std::domain_error(
"key not present in map");
65 typename map_type::iterator found = this->find(key);
66 if (found==this->end())
67 throw std::domain_error(
"key not present in map");
76 typename map_type::const_iterator found = this->find(key);
77 return found==this->end() ? dflt : found->second;
80 typename map_type::iterator found = this->find(key);
81 return found==this->end() ? dflt : found->second;
89 bool exists(
const Key &key)
const {
return this->find(key)!=this->end(); }