Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
memory.hh
Go to the documentation of this file.
1 #ifndef VCSN_MISC_MEMORY_HH
2 # define VCSN_MISC_MEMORY_HH
3 
4 # include <map>
5 # include <memory>
6 # include <utility> // std::forward
7 
8 namespace vcsn
9 {
12  template <typename SharedPtr, typename... Args>
13  inline
14  SharedPtr
15  make_shared_ptr(Args&&... args)
16  {
17  using type = typename SharedPtr::element_type;
18  return std::make_shared<type>(std::forward<Args>(args)...);
19  }
20 
22  inline
23  int address(const void* t)
24  {
25  static std::map<const void*, int> addresses;
26  auto p = addresses.emplace(t, 0);
27  if (p.second)
28  p.first->second = addresses.size();
29  return p.first->second;
30  }
31 
32  template <typename T>
33  inline
34  int address(T* t)
35  {
36  return address((const void*)t);
37  }
38 
39  template <typename T>
40  inline
41  int address(const T& t)
42  {
43  return address(&t);
44  }
45 }
46 
47 #endif // !VCSN_MISC_MEMORY_HH
int address(const void *t)
Name pointers, to make them easier to read.
Definition: memory.hh:23
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:15