![]() |
![]() |
00001 #ifndef FWCore_Utilities_clone_ptr_h 00002 #define FWCore_Utilities_clone_ptr_h 00003 00004 #include<memory> 00005 #include "FWCore/Utilities/interface/GCC11Compatibility.h" 00006 00007 namespace extstd { 00008 00009 /* modify unique_ptr behaviour adding a "cloning" copy-constructor and assignment-operator 00010 */ 00011 template<typename T> 00012 struct clone_ptr : public std::unique_ptr<T> { 00013 00014 template<typename... Args> 00015 explicit clone_ptr(Args&& ... args) noexcept : std::unique_ptr<T>(std::forward<Args>(args)...){} 00016 00017 clone_ptr(clone_ptr const & rh) : std::unique_ptr<T>(rh? rh->clone() : nullptr){} 00018 clone_ptr(clone_ptr && rh) noexcept : std::unique_ptr<T>(std::move(rh)) {} 00019 00020 clone_ptr & operator=(clone_ptr const & rh) { 00021 if (&rh!=this) this->reset(rh? rh->clone() : nullptr); 00022 return *this; 00023 } 00024 clone_ptr & operator=(clone_ptr && rh) noexcept { 00025 if (&rh!=this) std::unique_ptr<T>::operator=(std::move(rh)); 00026 return *this; 00027 } 00028 00029 00030 template<typename U> 00031 clone_ptr(clone_ptr<U> const & rh) : std::unique_ptr<T>(rh ? rh->clone() : nullptr){} 00032 template<typename U> 00033 clone_ptr(clone_ptr<U> && rh) noexcept : std::unique_ptr<T>(std::move(rh)) {} 00034 00035 template<typename U> 00036 clone_ptr & operator=(clone_ptr<U> const & rh) { 00037 if (&rh!=this) this->reset(rh? rh->clone() : nullptr); 00038 return *this; 00039 } 00040 template<typename U> 00041 clone_ptr & operator=(clone_ptr<U> && rh) noexcept { 00042 if (&rh!=this) std::unique_ptr<T>::operator=(std::move(rh)); 00043 return *this; 00044 } 00045 00046 }; 00047 00048 } 00049 00050 #endif