diff --git a/src/identity.cc b/src/identity.cc index 927e0b7..8d4fdb0 100644 --- a/src/identity.cc +++ b/src/identity.cc @@ -24,7 +24,7 @@ namespace pEp } template<> - ::pEp_identity* Wrapper<::pEp_identity*>::copy_out() + ::pEp_identity* Wrapper<::pEp_identity*>::copy_out() const { return identity_dup(value); } diff --git a/src/wrapper.hh b/src/wrapper.hh index 89dd176..ffb78c2 100644 --- a/src/wrapper.hh +++ b/src/wrapper.hh @@ -62,11 +62,7 @@ public: template Wrapper(Args... args) : value{ this->_new(args...) } {} - // no implicit copying... (yet?) - Wrapper(const Wrapper&) = delete; - void operator=(const Wrapper&) = delete; - - // must be implemented separately for each T + // move is easy, efficient and generic: Wrapper(Wrapper&& victim) : value{ victim.value} { @@ -80,6 +76,18 @@ public: victim.value = nullptr; return *this; } + + Wrapper(const Wrapper& orig) + : value{ orig.copy_out() } + {} + + Wrapper& operator=(const Wrapper& orig) + { + if(&orig == this) return *this; + _free(value); + value = orig.copy_out(); + return *this; + } ~Wrapper() { @@ -107,7 +115,7 @@ public: // only implemented for the datatypes where necessay. // other implementations can follow if necessary. - T* copy_out(); + T* copy_out() const; protected: