CMS 3D CMS Logo

clone_ptr.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_clone_ptr_h
2 #define FWCore_Utilities_clone_ptr_h
3 
4 #include <memory>
5 
6 namespace extstd {
7 
8  /* modify unique_ptr behaviour adding a "cloning" copy-constructor and assignment-operator
9  */
10  template <typename T>
11  struct clone_ptr : public std::unique_ptr<T> {
12  template <typename... Args>
13  explicit clone_ptr(Args&&... args) noexcept : std::unique_ptr<T>(std::forward<Args>(args)...) {}
14 
15  clone_ptr(clone_ptr const& rh) : std::unique_ptr<T>(rh ? rh->clone() : nullptr) {}
16  clone_ptr(clone_ptr&& rh) noexcept : std::unique_ptr<T>(std::move(rh)) {}
17 
19  if (&rh != this)
20  this->reset(rh ? rh->clone() : nullptr);
21  return *this;
22  }
24  if (&rh != this)
25  std::unique_ptr<T>::operator=(std::move(rh));
26  return *this;
27  }
28 
29  template <typename U>
30  clone_ptr(clone_ptr<U> const& rh) : std::unique_ptr<T>(rh ? rh->clone() : nullptr) {}
31  template <typename U>
32  clone_ptr(clone_ptr<U>&& rh) noexcept : std::unique_ptr<T>(std::move(rh)) {}
33 
34  template <typename U>
36  if (&rh != this)
37  this->reset(rh ? rh->clone() : nullptr);
38  return *this;
39  }
40  template <typename U>
42  if (&rh != this)
43  std::unique_ptr<T>::operator=(std::move(rh));
44  return *this;
45  }
46  };
47 
48 } // namespace extstd
49 
50 #endif
clone_ptr & operator=(clone_ptr &&rh) noexcept
Definition: clone_ptr.h:23
clone_ptr & operator=(clone_ptr< U > const &rh)
Definition: clone_ptr.h:35
clone_ptr(Args &&...args) noexcept
Definition: clone_ptr.h:13
clone_ptr & operator=(clone_ptr const &rh)
Definition: clone_ptr.h:18
#define nullptr
clone_ptr(clone_ptr const &rh)
Definition: clone_ptr.h:15
clone_ptr(clone_ptr< U > &&rh) noexcept
Definition: clone_ptr.h:32
clone_ptr(clone_ptr< U > const &rh)
Definition: clone_ptr.h:30
#define noexcept
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
clone_ptr & operator=(clone_ptr< U > &&rh) noexcept
Definition: clone_ptr.h:41
long double T
void reset(double vett[256])
Definition: TPedValues.cc:11
def move(src, dest)
Definition: eostools.py:511
clone_ptr(clone_ptr &&rh) noexcept
Definition: clone_ptr.h:16