From 40466e02c3ab7ef31183158103e3ef7536248753 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 29 Feb 2012 10:57:43 +0200 Subject: Support for C++11 std::unique_ptr as object pointer This includes the odb::lazy_unique_ptr implementation. --- odb/pointer-traits.hxx | 55 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'odb/pointer-traits.hxx') 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 #include // operators new/delete -#include // std::auto_ptr, std::shared_ptr (C++11) +#include // std::auto_ptr, std::unique_ptr, std::shared_ptr/weak_ptr #include // std::size_t #include // ODB_CXX11 @@ -193,10 +193,59 @@ namespace odb #ifdef ODB_CXX11 + // Specialization for C++11 std::unique_ptr. + // + template + class pointer_traits> + { + public: + static const pointer_kind kind = pk_unique; + static const bool lazy = false; + + typedef T element_type; + typedef std::unique_ptr pointer_type; + typedef std::unique_ptr const_pointer_type; + typedef smart_ptr_guard 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 - class pointer_traits > + class pointer_traits> { public: static const pointer_kind kind = pk_shared; @@ -252,7 +301,7 @@ namespace odb // Specialization for C++11 std::weak_ptr. // template - class pointer_traits > + class pointer_traits> { public: static const pointer_kind kind = pk_weak; -- cgit v1.1