Vcsn  2.2a
Be Rational
map.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <set>
5 
7 
8 namespace std
9 {
10 
11  /*------------------------.
12  | hash(map<Key, Value>). |
13  `------------------------*/
14 
15  template <typename Key, typename Value, typename Compare, typename Alloc>
16  struct hash<map<Key, Value, Compare, Alloc>>
17  {
18  size_t operator()(const map<Key, Value, Compare, Alloc>& m) const
19  {
20  size_t res = 0;
21  for (const auto& kv: m)
22  {
23  hash_combine(res, kv.first);
24  hash_combine(res, kv.second);
25  }
26  return res;
27  }
28  };
29 }
30 
31 namespace vcsn
32 {
33 
35  template <typename Key, typename Value, typename Compare, typename Alloc>
36  inline
37  bool
38  has(const std::map<Key, Value, Compare, Alloc>& s, const Key& e)
39  {
40  return s.find(e) != std::end(s);
41  }
42 
44  template <typename Key, typename Value, typename Comp, typename Alloc>
45  std::set<typename std::map<Key, Value, Comp, Alloc>::mapped_type>
46  image(const std::map<Key, Value, Comp, Alloc>& m)
47  {
48  std::set<typename std::map<Key, Value, Comp, Alloc>::mapped_type> res;
49  for (const auto& p: m)
50  res.insert(p.second);
51  return res;
52  }
53 }
std::set< typename std::map< Key, Value, Comp, Alloc >::mapped_type > image(const std::map< Key, Value, Comp, Alloc > &m)
The set of values of a map.
Definition: map.hh:46
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
Definition: setalpha.hh:25
size_t operator()(const map< Key, Value, Compare, Alloc > &m) const
Definition: map.hh:18
auto map(const std::tuple< Ts... > &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
Definition: tuple.hh:160
STL namespace.
void hash_combine(std::size_t &seed, const T &v)
Definition: functional.hh:32
Definition: a-star.hh:8