From 8a9e1081c026a092c7dfb28fbd079b88850c7233 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 2 Mar 2012 12:34:54 +0200 Subject: Portability workarounds for incomplete C++11 support in VC++ and old GCC --- odb/lazy-ptr.hxx | 63 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 9 deletions(-) (limited to 'odb/lazy-ptr.hxx') diff --git a/odb/lazy-ptr.hxx b/odb/lazy-ptr.hxx index 0e44066..12acbb6 100644 --- a/odb/lazy-ptr.hxx +++ b/odb/lazy-ptr.hxx @@ -78,7 +78,7 @@ namespace odb template void reset (database_type&, const ID&); template void reset (database_type&, Y*); -#ifdef ODB_CXX11 +#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT template #else template @@ -193,7 +193,7 @@ namespace odb void reset (database_type&, T*); template void reset (database_type&, std::auto_ptr&); -#ifdef ODB_CXX11 +#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT template #else template @@ -229,7 +229,9 @@ namespace odb typedef D deleter_type; /*constexpr*/ lazy_unique_ptr () /*noexcept*/; +#ifdef ODB_CXX11_NULLPTR /*constexpr*/ lazy_unique_ptr (std::nullptr_t) /*noexcept*/; +#endif explicit lazy_unique_ptr (pointer) /*noexcept*/; // For now assume D is non-reference. @@ -241,14 +243,24 @@ namespace odb template lazy_unique_ptr (lazy_unique_ptr&&) /*noexcept*/; template lazy_unique_ptr (std::auto_ptr&&) /*noexcept*/; +#ifdef ODB_CXX11_NULLPTR lazy_unique_ptr& operator= (std::nullptr_t) /*noexcept*/; +#endif lazy_unique_ptr& operator= (lazy_unique_ptr&&) /*noexcept*/; template lazy_unique_ptr& operator= (lazy_unique_ptr&&) /*noexcept*/; T& operator* () const; pointer operator-> () const /*noexcept*/; pointer get () const /*noexcept*/; +#ifdef ODB_CXX11_EXPLICIT_CONVERSION_OPERATOR explicit operator bool() const /*noexcept*/; +#else + typedef std::unique_ptr lazy_unique_ptr::*unspecified_bool_type; + operator unspecified_bool_type () const + { + return (p_ || i_) ? &lazy_unique_ptr::p_ : 0; + } +#endif pointer release () /*noexcept*/; void reset (pointer = pointer ()) /*noexcept*/; @@ -257,8 +269,14 @@ namespace odb deleter_type& get_deleter () /*noexcept*/; const deleter_type& get_deleter () const /*noexcept*/; +#ifdef ODB_CXX11_DELETED_FUNCTION lazy_unique_ptr (const lazy_unique_ptr&) = delete; lazy_unique_ptr& operator= (const lazy_unique_ptr&) = delete; +#else + private: + lazy_unique_ptr (const lazy_unique_ptr&); + lazy_unique_ptr& operator= (const lazy_unique_ptr&); +#endif // Initialization/assignment from unique_ptr. // @@ -299,7 +317,11 @@ namespace odb template void reset (database_type&, std::unique_ptr&&); template void reset (database_type&, std::auto_ptr&&); +#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT template +#else + template +#endif typename object_traits::id_type object_id () const; database_type& database () const; @@ -328,20 +350,22 @@ namespace odb template bool operator== (const lazy_unique_ptr&, const lazy_unique_ptr&); + template + bool operator!= (const lazy_unique_ptr&, const lazy_unique_ptr&); + +#ifdef ODB_CXX11_NULLPTR template bool operator== (const lazy_unique_ptr&, std::nullptr_t) /*noexcept*/; template bool operator== (std::nullptr_t, const lazy_unique_ptr&) /*noexcept*/; - template - bool operator!= (const lazy_unique_ptr&, const lazy_unique_ptr&); - template bool operator!= (const lazy_unique_ptr&, std::nullptr_t) /*noexcept*/; template bool operator!= (std::nullptr_t, const lazy_unique_ptr&) /*noexcept*/; +#endif // C++11 std::shared_ptr lazy version. // @@ -357,12 +381,16 @@ namespace odb typedef T element_type; /*constexpr*/ lazy_shared_ptr () /*noexcept*/; +#ifdef ODB_CXX11_NULLPTR /*constexpr*/ lazy_shared_ptr (std::nullptr_t) /*noexcept*/; +#endif template explicit lazy_shared_ptr (Y*); template lazy_shared_ptr (Y*, D); template lazy_shared_ptr (Y*, D, A); +#ifdef ODB_CXX11_NULLPTR template lazy_shared_ptr (std::nullptr_t, D); template lazy_shared_ptr (std::nullptr_t, D, A); +#endif template lazy_shared_ptr (const lazy_shared_ptr&, T*) /*noexcept*/; lazy_shared_ptr (const lazy_shared_ptr&) /*noexcept*/; @@ -393,8 +421,15 @@ namespace odb T* operator-> () const /*noexcept*/; long use_count () const /*noexcept*/; bool unique () const /*noexcept*/; - +#ifdef ODB_CXX11_EXPLICIT_CONVERSION_OPERATOR explicit operator bool () const /*noexcept*/; +#else + typedef std::shared_ptr lazy_shared_ptr::*unspecified_bool_type; + operator unspecified_bool_type () const + { + return (p_ || i_) ? &lazy_shared_ptr::p_ : 0; + } +#endif // owner_before () is not provded. @@ -446,7 +481,11 @@ namespace odb template void reset (database_type&, const std::shared_ptr&); template void reset (database_type&, std::shared_ptr&&); +#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT template +#else + template +#endif typename object_traits::id_type object_id () const; database_type& database () const; @@ -474,20 +513,22 @@ namespace odb template bool operator== (const lazy_shared_ptr&, const lazy_shared_ptr&) /*noexcept*/; + template + bool operator!= (const lazy_shared_ptr&, const lazy_shared_ptr&) /*noexcept*/; + +#ifdef ODB_CXX11_NULLPTR template bool operator== (const lazy_shared_ptr&, std::nullptr_t) /*noexcept*/; template bool operator== (std::nullptr_t, const lazy_shared_ptr&) /*noexcept*/; - template - bool operator!= (const lazy_shared_ptr&, const lazy_shared_ptr&) /*noexcept*/; - template bool operator!= (const lazy_shared_ptr&, std::nullptr_t) /*noexcept*/; template bool operator!= (std::nullptr_t, const lazy_shared_ptr&) /*noexcept*/; +#endif // C++11 std::weak_ptr lazy version. // @@ -563,7 +604,11 @@ namespace odb // The object_id() function can only be called when the object is // persistent, or: expired() XOR loaded() (can use != for XOR). // +#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT template +#else + template +#endif typename object_traits::id_type object_id () const; database_type& database () const; -- cgit v1.1