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 
13  template<typename... Args>
14  explicit clone_ptr(Args&& ... args) noexcept : std::unique_ptr<T>(std::forward<Args>(args)...){}
15 
16  clone_ptr(clone_ptr const & rh) : std::unique_ptr<T>(rh? rh->clone() : nullptr){}
17  clone_ptr(clone_ptr && rh) noexcept : std::unique_ptr<T>(std::move(rh)) {}
18 
19  clone_ptr & operator=(clone_ptr const & rh) {
20  if (&rh!=this) this->reset(rh? rh->clone() : nullptr);
21  return *this;
22  }
24  if (&rh!=this) std::unique_ptr<T>::operator=(std::move(rh));
25  return *this;
26  }
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) this->reset(rh? rh->clone() : nullptr);
37  return *this;
38  }
39  template<typename U>
41  if (&rh!=this) std::unique_ptr<T>::operator=(std::move(rh));
42  return *this;
43  }
44 
45  };
46 
47 }
48 
49 #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:14
clone_ptr & operator=(clone_ptr const &rh)
Definition: clone_ptr.h:19
#define noexcept
clone_ptr(clone_ptr const &rh)
Definition: clone_ptr.h:16
#define nullptr
clone_ptr(clone_ptr< U > &&rh) noexcept
Definition: clone_ptr.h:32
clone_ptr(clone_ptr< U > const &rh)
Definition: clone_ptr.h:30
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
clone_ptr & operator=(clone_ptr< U > &&rh) noexcept
Definition: clone_ptr.h:40
long double T
void reset(double vett[256])
Definition: TPedValues.cc:11
def move(src, dest)
Definition: eostools.py:510
clone_ptr(clone_ptr &&rh) noexcept
Definition: clone_ptr.h:17