Vcsn  2.2
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  inline
13  SharedPtr
14  make_shared_ptr(Args&&... args)
15  {
16  using type = typename SharedPtr::element_type;
17  return std::make_shared<type>(std::forward<Args>(args)...);
18  }
19 
21  inline
22  int address(const void* t)
23  {
24  static std::map<const void*, int> addresses;
25  auto p = addresses.emplace(t, 0);
26  if (p.second)
27  p.first->second = addresses.size();
28  return p.first->second;
29  }
30 
31  template <typename T>
32  inline
33  int address(T* t)
34  {
35  return address((const void*)t);
36  }
37 
38  template <typename T>
39  inline
40  int address(const T& t)
41  {
42  return address(&t);
43  }
44 }
Definition: a-star.hh:8
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:14
int address(const void *t)
Name pointers, to make them easier to read.
Definition: memory.hh:22