Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
944a895efea26ac3649351325d0da2c52f0dade9
[simgrid.git] / src / simgrid / util.hpp
1 /* Copyright (c) 2015. The SimGrid Team.
2  * All rights reserved. */
3
4 #ifndef SIMGRID_UTIL_HTPP
5 #define SIMGRID_UTIL_HTPP
6
7 #include <algorithm>
8
9 namespace simgrid {
10 namespace util {
11
12 /** Find a pointer to a value stores in a map (or nullptr) */
13 template<typename C, typename K>
14 inline
15 typename C::mapped_type* find_map_ptr(C& c, K const& k)
16 {
17   typename C::iterator i = c.find(k);
18   if (i == c.end())
19     return nullptr;
20   else
21     return &i->second;
22 }
23
24 template<typename C, typename K>
25 inline
26 typename C::mapped_type const* find_map_ptr(C const& c, K const& k)
27 {
28   typename C::const_iterator i = c.find(k);
29   if (i == c.end())
30     return nullptr;
31   else
32     return &i->second;
33 }
34
35 }
36 }
37
38 #endif