diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-10-14 15:17:31 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-10-14 15:17:31 +0200 |
commit | f18ea631bbe47a116a6b8ad6da5ab10a5be8158f (patch) | |
tree | ab57a8cbb4e5a450b2f7ffd31f78afba6e597205 | |
parent | ad515f85e807f8d21a1b70f5ed288705e0f2f531 (diff) |
Fix transfer_ptr not to rely on copy elision
-rw-r--r-- | odb/details/transfer-ptr.hxx | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/odb/details/transfer-ptr.hxx b/odb/details/transfer-ptr.hxx index 2e40e29..13f113e 100644 --- a/odb/details/transfer-ptr.hxx +++ b/odb/details/transfer-ptr.hxx @@ -30,9 +30,27 @@ namespace odb #ifdef ODB_CXX11_NULLPTR transfer_ptr (std::nullptr_t): p_ (0) {} #endif - template <typename T1> transfer_ptr (std::unique_ptr<T1>&& p): p_ (p.release ()) {} + + private: + transfer_ptr (const transfer_ptr&); + transfer_ptr& operator= (const transfer_ptr&); + + public: + transfer_ptr (transfer_ptr&& p): p_ (p.transfer ()) {} +#else + private: + transfer_ptr& operator= (const transfer_ptr&); + + public: + // In our usage transfer_ptr is always created implicitly and + // never const. So while this is not very clean, it is legal. + // Plus it will all go away once we drop C++98 (I can hardly + // wait). + // + transfer_ptr (const transfer_ptr& p) + : p_ (const_cast<transfer_ptr&> (p).transfer ()) {} #endif ~transfer_ptr () {delete p_;} |