Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Concatenate nested namespaces (sonar).
[simgrid.git] / src / simgrid / util.hpp
1 /* Copyright (c) 2015-2022. 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::util {
13
14 /** Find a pointer to a value stores in a map (or nullptr) */
15 template<typename C, typename K>
16 inline XBT_PRIVATE
17 typename C::mapped_type* find_map_ptr(C& c, K const& k)
18 {
19   auto i = c.find(k);
20   if (i == c.end())
21     return nullptr;
22   else
23     return &i->second;
24 }
25
26 template<typename C, typename K>
27 inline XBT_PRIVATE
28 typename C::mapped_type const* find_map_ptr(C const& c, K const& k)
29 {
30   typename C::const_iterator i = c.find(k);
31   if (i == c.end())
32     return nullptr;
33   else
34     return &i->second;
35 }
36
37 } // namespace simgrid::util
38
39 #endif