Skip to content
Snippets Groups Projects
Commit 1039a784 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

redesign clone helper template function

parent c4b915de
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -12,14 +12,14 @@ ...@@ -12,14 +12,14 @@
   
namespace ext { namespace ext {
   
template<class T, typename std::enable_if< ! ext::has_clone<T>::value >::type* = nullptr> template < class T, typename std::enable_if < ! ext::has_clone < T >::value >::type * = nullptr >
T* clone(const T * const tmp) { auto clone ( T && tmp ) {
return new T(*tmp); return new typename std::decay < T >::type ( std::forward < T > ( tmp ) );
} }
   
template<class T, typename std::enable_if< ext::has_clone<T>::value >::type* = nullptr> template < class T, typename std::enable_if < ext::has_clone < T >::value >::type * = nullptr >
T* clone(const T * const tmp) { auto clone ( T && tmp ) {
return tmp->clone(); return std::forward < T > ( tmp ).clone ( );
} }
   
} /* namespace ext */ } /* namespace ext */
......
...@@ -130,7 +130,7 @@ private: ...@@ -130,7 +130,7 @@ private:
   
T * tmp = m_Data; T * tmp = m_Data;
detach ( ); detach ( );
tmp = ext::clone ( tmp ); tmp = ext::clone ( * tmp );
tmp->m_UseCount = 0; tmp->m_UseCount = 0;
attach ( tmp ); attach ( tmp );
} }
...@@ -253,7 +253,7 @@ private: ...@@ -253,7 +253,7 @@ private:
   
typename cow_shared_ptr < T >::cow_shared_ptr_data * tmp = m_Data; typename cow_shared_ptr < T >::cow_shared_ptr_data * tmp = m_Data;
detach ( ); detach ( );
attach ( new cow_shared_ptr_data ( ext::clone ( tmp->m_Data ) ) ); attach ( new cow_shared_ptr_data ( ext::clone ( * tmp->m_Data ) ) );
} }
   
cow_shared_ptr_data * m_Data; cow_shared_ptr_data * m_Data;
...@@ -281,7 +281,7 @@ public: ...@@ -281,7 +281,7 @@ public:
smart_ptr ( smart_ptr < R > other ) : m_Data ( other.release ( ) ) { smart_ptr ( smart_ptr < R > other ) : m_Data ( other.release ( ) ) {
} }
   
smart_ptr ( const smart_ptr & other ) : m_Data ( ext::clone ( other.m_Data ) ) { smart_ptr ( const smart_ptr & other ) : m_Data ( ext::clone ( * other.m_Data ) ) {
} }
   
smart_ptr ( smart_ptr && other ) noexcept : m_Data ( other.release ( ) ) { smart_ptr ( smart_ptr && other ) noexcept : m_Data ( other.release ( ) ) {
...@@ -295,7 +295,7 @@ public: ...@@ -295,7 +295,7 @@ public:
if ( this == & other ) return * this; if ( this == & other ) return * this;
   
delete m_Data; delete m_Data;
m_Data = ext::clone ( other.m_Data ); m_Data = ext::clone ( * other.m_Data );
   
return * this; return * this;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment