Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to fix some compilation erros
[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 <algorithm>
11
12 #include <xbt/base.h>
13
14 namespace simgrid {
15 namespace util {
16
17 /** Find a pointer to a value stores in a map (or nullptr) */
18 template<typename C, typename K>
19 inline XBT_PRIVATE
20 typename C::mapped_type* find_map_ptr(C& c, K const& k)
21 {
22   typename C::iterator i = c.find(k);
23   if (i == c.end())
24     return nullptr;
25   else
26     return &i->second;
27 }
28
29 template<typename C, typename K>
30 inline XBT_PRIVATE
31 typename C::mapped_type const* find_map_ptr(C const& c, K const& k)
32 {
33   typename C::const_iterator i = c.find(k);
34   if (i == c.end())
35     return nullptr;
36   else
37     return &i->second;
38 }
39
40 }
41 }
42
43 #endif