Vcsn  2.4
Be Rational
memory.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <utility> // std::forward
6 
7 namespace vcsn
8 {
11  template <typename SharedPtr, typename... Args>
12  SharedPtr
13  make_shared_ptr(Args&&... args)
14  {
15  using type = typename SharedPtr::element_type;
16  return std::make_shared<type>(std::forward<Args>(args)...);
17  }
18 
20  inline
21  unsigned address(const void* t)
22  {
23  static auto addresses = std::map<const void*, unsigned>{};
24  auto p = addresses.emplace(t, 0);
25  if (p.second)
26  p.first->second = addresses.size();
27  return p.first->second;
28  }
29 
30  template <typename T>
31  unsigned address(T* t)
32  {
33  return address(static_cast<const void*>(t));
34  }
35 
36  template <typename T>
37  unsigned address(const T& t)
38  {
39  return address(&t);
40  }
41 }
SharedPtr make_shared_ptr(Args &&...args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
Definition: memory.hh:13
unsigned address(const void *t)
Name pointers, to make them easier to read.
Definition: memory.hh:21
Definition: a-star.hh:8