aboutsummaryrefslogtreecommitdiff
path: root/odb/details/unique-ptr.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-02 14:11:03 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-02 14:11:03 +0200
commit64cfe5e150e2d3e58dde1a6701d8c734c20e0848 (patch)
tree600adad0eb7f41cd5e1a4e34a28922db4024684f /odb/details/unique-ptr.hxx
parent8a9e1081c026a092c7dfb28fbd079b88850c7233 (diff)
Reimplement C++11 support to be header-only
This way, the same build of the runtime libraries can be used in both C++98 and C++11 modes. This is important for when runtimes are installed or packaged.
Diffstat (limited to 'odb/details/unique-ptr.hxx')
-rw-r--r--odb/details/unique-ptr.hxx80
1 files changed, 80 insertions, 0 deletions
diff --git a/odb/details/unique-ptr.hxx b/odb/details/unique-ptr.hxx
new file mode 100644
index 0000000..ab08d51
--- /dev/null
+++ b/odb/details/unique-ptr.hxx
@@ -0,0 +1,80 @@
+// file : odb/details/unique-ptr.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_DETAILS_UNIQUE_PTR_HXX
+#define ODB_DETAILS_UNIQUE_PTR_HXX
+
+#include <odb/pre.hxx>
+
+namespace odb
+{
+ namespace details
+ {
+ template <typename T>
+ class unique_ptr
+ {
+ public:
+ typedef T element_type;
+
+ explicit unique_ptr (T* p = 0): p_ (p) {}
+ ~unique_ptr () {delete p_;}
+
+ private:
+ unique_ptr (const unique_ptr&);
+ unique_ptr& operator= (const unique_ptr&);
+
+ public:
+ T*
+ operator-> () const {return p_;}
+
+ T&
+ operator* () const {return *p_;}
+
+ typedef T* unique_ptr::*unspecified_bool_type;
+ operator unspecified_bool_type () const
+ {
+ return p_ != 0 ? &unique_ptr::p_ : 0;
+ }
+
+ T*
+ get () const {return p_;}
+
+ void
+ reset (T* p = 0)
+ {
+ delete p_;
+ p_ = p;
+ }
+
+ T*
+ release ()
+ {
+ T* r (p_);
+ p_ = 0;
+ return r;
+ }
+
+ private:
+ T* p_;
+ };
+
+ template <typename T1, typename T2>
+ inline bool
+ operator== (const unique_ptr<T1>& a, const unique_ptr<T2>& b)
+ {
+ return a.get () == b.get ();
+ }
+
+ template <typename T1, typename T2>
+ inline bool
+ operator!= (const unique_ptr<T1>& a, const unique_ptr<T2>& b)
+ {
+ return a.get () != b.get ();
+ }
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_DETAILS_UNIQUE_PTR_HXX