sharedPointer_std.hh

Go to the documentation of this file.
1 
4 #pragma once
5 
6 
7 #include <memory>
8 
9 namespace concepts {
10 
11  // ********************************************************** null_deleter **
12 
13  struct null_deleter
14  {
15  void operator()(void const *) const
16  {
17  }
18  };
19 
20  // ******************************************************************* RCP **
21 
27  template<class T>
28  class RCP : public std::shared_ptr<T>
29  {
30  public:
32  RCP() : std::shared_ptr<T>() {}
33 
46  explicit RCP(T* x) : std::shared_ptr<T>(x) {}
47 
48  RCP(std::shared_ptr<T>& x) : std::shared_ptr<T>(x) {}
49 
50  template<class F>
51  RCP(const std::shared_ptr<F>& x) : std::shared_ptr<T>(x) {}
52 
54  template<class F, class G>
55  RCP(F x, G y) : std::shared_ptr<T>(x, y) {}
56 
58  {
59  RCP<T>(x).swap(*this);
60  return *this;
61  }
62 
63  template<class F>
64  RCP<T>& operator=(const std::shared_ptr<F> x)
65  {
66  RCP<T>(x).swap(*this);
67  return *this;
68  }
69 
70  // this conversion operator is already implemented for shared_ptr
71  #if 0
72  // template function for implicit conversion ops.
73  template<class NewType>
74  operator RCP<NewType>()
75  {
76  return RCP<NewType>( std::shared_ptr<NewType>(*this) );
77  }
78  #endif
79  };
80 
81  // *************************************************************** makeRCP **
82 
101  template <class T>
102  RCP<T> makeRCP(T* x)
103  {
104  return RCP<T>(x);
105  }
106 
107  // ********************************************************** makeRCP_weak **
108 
121  template<class T>
122  RCP<T> makeRCP_weak(T* x)
123  {
124  return RCP<T>(x, null_deleter());
125  }
126 
127 #if 1
128  template<class T>
129  RCP<const T> makecRCP_weak(T* x) // create a const pointer
130  {
131  return RCP<const T>(x, null_deleter());
132  }
133 #endif
134 
135 
136 } // namespace concepts
void operator()(void const *) const
RCP(F x, G y)
Constructor which includes the deleter G.
RCP< T > makeRCP_weak(T *x)
Function to create a RCP without deleting the object in the destructor.
RCP< const T > makecRCP_weak(T *x)
RCP()
Default constructor.
RCP< T > & operator=(const std::shared_ptr< F > x)
RCP< T > makeRCP(T *x)
Function to create a RCP which deletes the object when no RCP points on it anymore.
Reference-counting pointer.
Definition: bf_iddiv.hh:15
RCP(T *x)
Constructor for a simple pointer, which will be deleted by the RCP.
RCP< T > & operator=(const RCP< T > x)
RCP(std::shared_ptr< T > &x)
RCP(const std::shared_ptr< F > &x)
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich