Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'energy-pstate' of https://github.com/Takishipp/simgrid into Takishipp...
[simgrid.git] / src / simgrid / util.hpp
1 /* Copyright (c) 2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_UTIL_HTPP
8 #define SIMGRID_UTIL_HTPP
9
10 #include <xbt/base.h>
11
12 namespace simgrid {
13 namespace util {
14
15 /** Find a pointer to a value stores in a map (or nullptr) */
16 template<typename C, typename K>
17 inline XBT_PRIVATE
18 typename C::mapped_type* find_map_ptr(C& c, K const& k)
19 {
20   typename C::iterator i = c.find(k);
21   if (i == c.end())
22     return nullptr;
23   else
24     return &i->second;
25 }
26
27 template<typename C, typename K>
28 inline XBT_PRIVATE
29 typename C::mapped_type const* find_map_ptr(C const& c, K const& k)
30 {
31   typename C::const_iterator i = c.find(k);
32   if (i == c.end())
33     return nullptr;
34   else
35     return &i->second;
36 }
37
38 }
39 }
40
41 #endif