Dune Core Modules (2.5.0)

shared_ptr.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_SHARED_PTR_HH
5 #define DUNE_SHARED_PTR_HH
6 
7 #include <memory>
8 
16 namespace Dune
17 {
18  // pull in default implementations
19  using std::shared_ptr;
20  using std::make_shared;
21 
50  template<class T>
51  struct null_deleter
52  {
53  void operator() (T*) const {}
54  };
55 
74  template<typename T>
75  inline shared_ptr<T> stackobject_to_shared_ptr(T & t)
76  {
77  return shared_ptr<T>(&t, null_deleter<T>());
78  }
79 
103  template<typename T, typename T2>
104  inline shared_ptr<T2> stackobject_to_shared_ptr(T & t)
105  {
106  return shared_ptr<T2>(dynamic_cast<T2*>(&t), null_deleter<T2>());
107  }
108 
109 
127  template<class T>
128  auto wrap_or_move(T&& t)
129  {
130  return std::make_shared<std::decay_t<T>>(std::forward<T>(t));
131  }
132 
150  template<class T>
151  auto wrap_or_move(T& t)
152  {
153  return stackobject_to_shared_ptr(t);
154  }
155 
156 }
157 #endif
Dune namespace.
Definition: alignment.hh:11
auto wrap_or_move(T &&t)
Capture R-value reference to shared_ptr.
Definition: shared_ptr.hh:128
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
implements the Deleter concept of shared_ptr without deleting anything
Definition: shared_ptr.hh:52
shared_ptr< T2 > stackobject_to_shared_ptr(T &t)
Create a shared_ptr to a base class for a stack-allocated object.
Definition: shared_ptr.hh:104
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)