diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-29 10:57:43 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-29 10:57:43 +0200 |
commit | 40466e02c3ab7ef31183158103e3ef7536248753 (patch) | |
tree | db4d542aae19b94e9be00636e9cf5b75c5c8cd7a /odb/pointer-traits.hxx | |
parent | 35a2460893ddfd006d9d85dcc6ab7a01c1ab9848 (diff) |
Support for C++11 std::unique_ptr as object pointer
This includes the odb::lazy_unique_ptr implementation.
Diffstat (limited to 'odb/pointer-traits.hxx')
-rw-r--r-- | odb/pointer-traits.hxx | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/odb/pointer-traits.hxx b/odb/pointer-traits.hxx index 07b396a..fbfa721 100644 --- a/odb/pointer-traits.hxx +++ b/odb/pointer-traits.hxx @@ -8,7 +8,7 @@ #include <odb/pre.hxx> #include <new> // operators new/delete -#include <memory> // std::auto_ptr, std::shared_ptr (C++11) +#include <memory> // std::auto_ptr, std::unique_ptr, std::shared_ptr/weak_ptr #include <cstddef> // std::size_t #include <odb/details/config.hxx> // ODB_CXX11 @@ -193,10 +193,59 @@ namespace odb #ifdef ODB_CXX11 + // Specialization for C++11 std::unique_ptr. + // + template <typename T, typename D> + class pointer_traits<std::unique_ptr<T, D>> + { + public: + static const pointer_kind kind = pk_unique; + static const bool lazy = false; + + typedef T element_type; + typedef std::unique_ptr<element_type, D> pointer_type; + typedef std::unique_ptr<const element_type, D> const_pointer_type; + typedef smart_ptr_guard<pointer_type> guard; + + static element_type* + get_ptr (const pointer_type& p) + { + return p.get (); + } + + static element_type& + get_ref (const pointer_type& p) + { + return *p; + } + + static bool + null_ptr (const pointer_type& p) + { + return !p; + } + + // cast() is not provided since it transfers the ownership. + // + + public: + static void* + allocate (std::size_t n) + { + return operator new (n); + } + + static void + free (void* p) + { + operator delete (p); + } + }; + // Specialization for C++11 std::shared_ptr. // template <typename T> - class pointer_traits<std::shared_ptr<T> > + class pointer_traits<std::shared_ptr<T>> { public: static const pointer_kind kind = pk_shared; @@ -252,7 +301,7 @@ namespace odb // Specialization for C++11 std::weak_ptr. // template <typename T> - class pointer_traits<std::weak_ptr<T> > + class pointer_traits<std::weak_ptr<T>> { public: static const pointer_kind kind = pk_weak; |