|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55568 - in sandbox/fmhess: boost/generic_ptr boost/generic_ptr/detail boost/smart_ptr libs/generic_ptr/test
From: fmhess_at_[hidden]
Date: 2009-08-13 12:40:17
Author: fmhess
Date: 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
New Revision: 55568
URL: http://svn.boost.org/trac/boost/changeset/55568
Log:
Added test for overload resolution based on generic pointers'
value_type, and fixed corresponding failures.
Text files modified:
sandbox/fmhess/boost/generic_ptr/asserting.hpp | 35 ++++++++++++-
sandbox/fmhess/boost/generic_ptr/cloning.hpp | 54 +++++++++++++++++++-
sandbox/fmhess/boost/generic_ptr/detail/util.hpp | 2
sandbox/fmhess/boost/generic_ptr/intrusive.hpp | 10 +--
sandbox/fmhess/boost/generic_ptr/monitor.hpp | 24 ++++++++-
sandbox/fmhess/boost/generic_ptr/nonnull.hpp | 35 ++++++++++++-
sandbox/fmhess/boost/generic_ptr/shared.hpp | 15 +---
sandbox/fmhess/boost/generic_ptr/throwing.hpp | 35 ++++++++++++-
sandbox/fmhess/boost/generic_ptr/weak.hpp | 14 +++--
sandbox/fmhess/boost/smart_ptr/shared_ptr.hpp | 8 +-
sandbox/fmhess/boost/smart_ptr/weak_ptr.hpp | 12 ++--
sandbox/fmhess/libs/generic_ptr/test/basic_generic_pointer_test.cpp | 101 +++++++++++++++++++++++++++------------
12 files changed, 263 insertions(+), 82 deletions(-)
Modified: sandbox/fmhess/boost/generic_ptr/asserting.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/asserting.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/asserting.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -18,6 +18,8 @@
#include <boost/generic_ptr/pointer_cast.hpp>
#include <boost/generic_ptr/pointer_traits.hpp>
#include <boost/mpl/identity.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/utility/swap.hpp>
namespace boost
@@ -42,16 +44,43 @@
asserting(): px()
{}
template<typename U>
- asserting( U p ): px( p )
+ asserting
+ (
+ U p
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px( p )
{}
+#ifndef BOOST_NO_SFINAE
template<typename U>
- asserting(const asserting<U> & other): px(other.px)
+ explicit asserting
+ (
+ U p
+ , typename disable_if<is_convertible<U, T> >::type * = 0
+ ): px( p )
+ {}
+#endif // BOOST_NO_SFINAE
+ template<typename U>
+ asserting
+ (
+ const asserting<U> & other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px(other.px)
{}
#ifndef BOOST_NO_RVALUE_REFERENCES
asserting(asserting && other): px(std::move(other.px))
{}
template<typename U>
- asserting(asserting<U> && other): px(std::move(other.px))
+ asserting
+ (
+ asserting<U> && other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px(std::move(other.px))
{}
#endif
Modified: sandbox/fmhess/boost/generic_ptr/cloning.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/cloning.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/cloning.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -23,7 +23,9 @@
#include <boost/noncopyable.hpp>
#include <boost/ptr_container/clone_allocator.hpp>
#include <boost/scoped_ptr.hpp>
+#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/remove_const.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/utility/swap.hpp>
namespace boost
@@ -168,7 +170,13 @@
cloning(): _clone_factory(), px()
{}
template<typename U>
- cloning( U p ):
+ cloning
+ (
+ U p
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ):
_clone_factory
(
typename generic_ptr::rebind<T, typename pointer_traits<U>::value_type>::other(p),
@@ -183,8 +191,34 @@
>(_clone_factory.get_pointer())
)
{}
+#ifndef BOOST_NO_SFINAE
+ template<typename U>
+ explicit cloning
+ (
+ U p
+ , typename disable_if<is_convertible<U, T> >::type * = 0
+ ):
+ _clone_factory
+ (
+ typename generic_ptr::rebind<T, typename pointer_traits<U>::value_type>::other(p),
+ default_cloning_deleter(),
+ default_cloner()
+ ),
+ px
+ (
+ static_pointer_cast
+ <
+ typename pointer_traits<U>::value_type
+ >(_clone_factory.get_pointer())
+ )
+ {}
+#endif // BOOST_NO_SFINAE
template<typename U, typename Deleter>
- cloning(U p, Deleter d):
+ cloning
+ (
+ U p,
+ Deleter d
+ ):
_clone_factory
(
typename generic_ptr::rebind<T, typename pointer_traits<U>::value_type>::other(p),
@@ -223,7 +257,13 @@
)
{}
template<typename U>
- cloning(const cloning<U> & other):
+ cloning
+ (
+ const cloning<U> & other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ):
_clone_factory(other._clone_factory),
px
(
@@ -299,7 +339,13 @@
detail::set_plain_old_pointer_to_null(other.px);
}
template<typename U>
- cloning(cloning<U> && other): _clone_factory(std::move(other._clone_factory)), px(std::move(other.px))
+ cloning
+ (
+ cloning<U> && other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): _clone_factory(std::move(other._clone_factory)), px(std::move(other.px))
{
detail::set_plain_old_pointer_to_null(other.px);
}
Modified: sandbox/fmhess/boost/generic_ptr/detail/util.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/detail/util.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/detail/util.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -32,4 +32,4 @@
} // namespace generic_ptr
} // namespace boost
-#endif // #ifndef BOOST_GENERIC_PTR_DETAIL_UTIL_HPP_INCLUDED
+#endif // BOOST_GENERIC_PTR_DETAIL_UTIL_HPP_INCLUDED
Modified: sandbox/fmhess/boost/generic_ptr/intrusive.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/intrusive.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/intrusive.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -26,7 +26,7 @@
#include <boost/generic_ptr/pointer_cast.hpp>
#include <boost/generic_ptr/pointer_traits.hpp>
#include <boost/mpl/identity.hpp>
-#include <boost/smart_ptr/detail/sp_convertible.hpp>
+#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/utility/swap.hpp>
@@ -106,13 +106,9 @@
#if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
template<class U>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+#if !defined( BOOST_NO_SFINAE )
- intrusive( intrusive<U> const & rhs, typename boost::detail::sp_enable_if_convertible
- <
- typename pointer_traits<U>::value_type,
- typename pointer_traits<T>::value_type
- >::type = boost::detail::sp_empty() )
+ intrusive( intrusive<U> const & rhs, typename enable_if<is_convertible<U,T> >::type * = 0 )
#else
Modified: sandbox/fmhess/boost/generic_ptr/monitor.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/monitor.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/monitor.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -20,6 +20,8 @@
#include <boost/generic_ptr/detail/unique_lock.hpp>
#include <boost/generic_ptr/shared.hpp>
#include <boost/mpl/identity.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/utility/swap.hpp>
namespace boost
@@ -66,16 +68,32 @@
monitor(): px(), _mutex_p()
{}
template<typename U>
- explicit monitor( U p, const shared<Mutex*> & mutex_p = shared<Mutex*>(new Mutex()) ): px( p ), _mutex_p(mutex_p)
+ explicit monitor
+ (
+ U p,
+ const shared<Mutex*> & mutex_p = shared<Mutex*>(new Mutex())
+ ): px( p ), _mutex_p(mutex_p)
{}
template<typename U>
- monitor(const monitor<U, Mutex> & other): px(other.px), _mutex_p(other._mutex_p)
+ monitor
+ (
+ const monitor<U, Mutex> & other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px(other.px), _mutex_p(other._mutex_p)
{}
#ifndef BOOST_NO_RVALUE_REFERENCES
monitor(monitor && other): px(std::move(other.px)), _mutex_p(std::move(other._mutex_p))
{}
template<typename U>
- monitor(monitor<U> && other): px(std::move(other.px)), _mutex_p(std::move(other._mutex_p))
+ monitor
+ (
+ monitor<U> && other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px(std::move(other.px)), _mutex_p(std::move(other._mutex_p))
{}
#endif
Modified: sandbox/fmhess/boost/generic_ptr/nonnull.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/nonnull.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/nonnull.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -18,6 +18,8 @@
#include <boost/generic_ptr/pointer_cast.hpp>
#include <boost/generic_ptr/pointer_traits.hpp>
#include <boost/mpl/identity.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/utility/swap.hpp>
namespace boost
@@ -40,18 +42,44 @@
};
template<typename U>
- nonnull( U p ): px( p )
+ nonnull
+ (
+ U p
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px( p )
{
if(get_plain_old_pointer(px) == 0)
{
throw std::invalid_argument("Attempted to create a generic_ptr::nonnull with a null pointer.");
}
}
+#ifndef BOOST_NO_SFINAE
template<typename U>
- nonnull(const nonnull<U> & other): px(other.px)
+ explicit nonnull
+ (
+ U p
+ , typename disable_if<is_convertible<U, T> >::type * = 0
+ ): px( p )
+ {
+ if(get_plain_old_pointer(px) == 0)
+ {
+ throw std::invalid_argument("Attempted to create a generic_ptr::nonnull with a null pointer.");
+ }
+ }
+#endif // BOOST_NO_SFINAE
+ template<typename U>
+ nonnull
+ (
+ const nonnull<U> & other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px(other.px)
{}
- // no move constructors because they could violate the nonnull invariant of the moved-from object
+ // no move from nonnull constructor because they could violate the nonnull invariant of the moved-from object
// default copy constructor and assignment operator are fine
@@ -147,6 +175,7 @@
mpl::identity<ToValueType> to_type_iden = mpl::identity<ToValueType>()
)
{
+ //FIXME: should check and throw proper exception on cast failure (cannot return zero for nonnull)
return dynamic_pointer_cast(p.get(), to_type_iden);
}
Modified: sandbox/fmhess/boost/generic_ptr/shared.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/shared.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/shared.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -45,7 +45,7 @@
#include <boost/throw_exception.hpp>
#include <boost/smart_ptr/detail/shared_count.hpp>
#include <boost/detail/workaround.hpp>
-#include <boost/smart_ptr/detail/sp_convertible.hpp>
+#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/utility/swap.hpp>
@@ -131,11 +131,6 @@
#endif
-template<typename Y, typename T>
-class sp_enable_if_convertible: public
- boost::detail::sp_enable_if_convertible<typename pointer_traits<Y>::value_type, typename pointer_traits<T>::value_type>
-{};
-
} // namespace detail
@@ -213,9 +208,9 @@
}
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+#if !defined( BOOST_NO_SFINAE )
- shared( shared<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
+ shared( shared<Y> const & r, typename enable_if<is_convertible<Y,T> >::type * = 0 )
#else
@@ -335,9 +330,9 @@
}
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+#if !defined( BOOST_NO_SFINAE )
- shared( shared<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
+ shared( shared<Y> && r, typename enable_if<is_convertible<Y,T> >::type * = 0 )
#else
Modified: sandbox/fmhess/boost/generic_ptr/throwing.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/throwing.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/throwing.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -17,6 +17,8 @@
#include <boost/generic_ptr/pointer_cast.hpp>
#include <boost/generic_ptr/pointer_traits.hpp>
#include <boost/mpl/identity.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/utility/swap.hpp>
#include <stdexcept>
@@ -42,16 +44,43 @@
throwing(): px()
{}
template<typename U>
- throwing( U p ): px( p )
+ throwing
+ (
+ U p
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px( p )
{}
+#ifndef BOOST_NO_SFINAE
template<typename U>
- throwing(const throwing<U> & other): px(other.px)
+ explicit throwing
+ (
+ U p
+ , typename disable_if<is_convertible<U, T> >::type * = 0
+ ): px( p )
+ {}
+#endif // BOOST_NO_SFINAE
+ template<typename U>
+ throwing
+ (
+ const throwing<U> & other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px(other.px)
{}
#ifndef BOOST_NO_RVALUE_REFERENCES
throwing(throwing && other): px(std::move(other.px))
{}
template<typename U>
- throwing(throwing<U> && other): px(std::move(other.px))
+ throwing
+ (
+ throwing<U> && other
+#ifndef BOOST_NO_SFINAE
+ , typename enable_if<is_convertible<U, T> >::type * = 0
+#endif // BOOST_NO_SFINAE
+ ): px(std::move(other.px))
{}
#endif
Modified: sandbox/fmhess/boost/generic_ptr/weak.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/weak.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/weak.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -17,6 +17,8 @@
#include <memory> // boost.TR1 include order fix
#include <boost/smart_ptr/detail/shared_count.hpp>
#include <boost/generic_ptr/shared.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/utility/swap.hpp>
#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
@@ -67,9 +69,9 @@
//
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+#if !defined( BOOST_NO_SFINAE )
- weak( weak<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
+ weak( weak<Y> const & r, typename enable_if<is_convertible<Y,T> >::type * = 0 )
#else
@@ -83,9 +85,9 @@
#ifndef BOOST_NO_RVALUE_REFERENCES
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+#if !defined( BOOST_NO_SFINAE )
- weak( weak<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
+ weak( weak<Y> && r, typename enable_if<is_convertible<Y,T> >::type * = 0 )
#else
@@ -114,9 +116,9 @@
#endif
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+#if !defined( BOOST_NO_SFINAE )
- weak( shared<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
+ weak( shared<Y> const & r, typename enable_if<is_convertible<Y,T> >::type * = 0 )
#else
Modified: sandbox/fmhess/boost/smart_ptr/shared_ptr.hpp
==============================================================================
--- sandbox/fmhess/boost/smart_ptr/shared_ptr.hpp (original)
+++ sandbox/fmhess/boost/smart_ptr/shared_ptr.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -68,8 +68,8 @@
shared_ptr(U *u, V v, W w): base_type(u, v, w)
{}
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
- shared_ptr( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
+#if !defined( BOOST_NO_SFINAE )
+ shared_ptr( shared_ptr<Y> const & r, typename enable_if<is_convertible<Y*, T*> >::type * = 0 )
#else
shared_ptr( shared_ptr<Y> const & r )
#endif
@@ -94,8 +94,8 @@
shared_ptr( shared_ptr && r ): base_type(std::move<base_type>(r))
{}
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
- shared_ptr( shared_ptr<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
+#if !defined( BOOST_NO_SFINAE )
+ shared_ptr( shared_ptr<Y> && r, typename enable_if<is_convertible<Y*, T*> >::type * = 0 )
#else
shared_ptr( shared_ptr<Y> && r )
#endif
Modified: sandbox/fmhess/boost/smart_ptr/weak_ptr.hpp
==============================================================================
--- sandbox/fmhess/boost/smart_ptr/weak_ptr.hpp (original)
+++ sandbox/fmhess/boost/smart_ptr/weak_ptr.hpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -24,16 +24,16 @@
weak_ptr() {}
weak_ptr(base_type const & b): base_type(b) {}
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
- weak_ptr( weak_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
+#if !defined( BOOST_NO_SFINAE )
+ weak_ptr( weak_ptr<Y> const & r, typename typename enable_if<is_convertible<Y*, T*> >::type * = 0 )
#else
weak_ptr( weak_ptr<Y> const & r )
#endif
:base_type(static_cast<generic_ptr::weak<Y*> const &>(r))
{}
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
- weak_ptr( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
+#if !defined( BOOST_NO_SFINAE )
+ weak_ptr( shared_ptr<Y> const & r, typename typename enable_if<is_convertible<Y*, T*> >::type * = 0 )
#else
weak_ptr( shared_ptr<Y> const & r )
#endif
@@ -41,8 +41,8 @@
{}
#ifndef BOOST_NO_RVALUE_REFERENCES
template<class Y>
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
- weak_ptr( weak_ptr<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
+#if !defined( BOOST_NO_SFINAE )
+ weak_ptr( weak_ptr<Y> && r, typename typename enable_if<is_convertible<Y*, T*> >::type * = 0 )
#else
weak_ptr( weak_ptr<Y> && r )
#endif
Modified: sandbox/fmhess/libs/generic_ptr/test/basic_generic_pointer_test.cpp
==============================================================================
--- sandbox/fmhess/libs/generic_ptr/test/basic_generic_pointer_test.cpp (original)
+++ sandbox/fmhess/libs/generic_ptr/test/basic_generic_pointer_test.cpp 2009-08-13 12:40:16 EDT (Thu, 13 Aug 2009)
@@ -20,6 +20,8 @@
#include <boost/generic_ptr/shared.hpp>
#include <boost/generic_ptr/throwing.hpp>
+namespace bgp = boost::generic_ptr;
+
class Y
{
public:
@@ -51,47 +53,47 @@
template<typename GenericPointer>
void rebind_test(GenericPointer &p)
{
- typedef typename boost::generic_ptr::rebind
+ typedef typename bgp::rebind
<
GenericPointer,
- const typename boost::generic_ptr::pointer_traits<GenericPointer>::value_type
+ const typename bgp::pointer_traits<GenericPointer>::value_type
>::other other_type;
- BOOST_TEST(typeid(const typename boost::generic_ptr::pointer_traits<GenericPointer>::value_type) ==
- typeid(typename boost::generic_ptr::pointer_traits<other_type>::value_type));
+ BOOST_TEST(typeid(const typename bgp::pointer_traits<GenericPointer>::value_type) ==
+ typeid(typename bgp::pointer_traits<other_type>::value_type));
}
template<typename GenericPointer>
void cast_test(GenericPointer &p)
{
- typedef typename boost::generic_ptr::rebind<GenericPointer, Y>::other pointer_to_y_type;
+ typedef typename bgp::rebind<GenericPointer, Y>::other pointer_to_y_type;
- pointer_to_y_type yp = boost::generic_ptr::static_pointer_cast<Y>(p);
- GenericPointer xp = boost::generic_ptr::static_pointer_cast
- <typename boost::generic_ptr::pointer_traits<GenericPointer>::value_type>(yp);
-
- yp = boost::generic_ptr::dynamic_pointer_cast<Y>(p);
- BOOST_TEST(boost::generic_ptr::get_plain_old_pointer(yp) != 0);
- xp = boost::generic_ptr::dynamic_pointer_cast
- <typename boost::generic_ptr::pointer_traits<GenericPointer>::value_type>(yp);
- BOOST_TEST(boost::generic_ptr::get_plain_old_pointer(xp) != 0);
+ pointer_to_y_type yp = bgp::static_pointer_cast<Y>(p);
+ GenericPointer xp = bgp::static_pointer_cast
+ <typename bgp::pointer_traits<GenericPointer>::value_type>(yp);
+
+ yp = bgp::dynamic_pointer_cast<Y>(p);
+ BOOST_TEST(bgp::get_plain_old_pointer(yp) != 0);
+ xp = bgp::dynamic_pointer_cast
+ <typename bgp::pointer_traits<GenericPointer>::value_type>(yp);
+ BOOST_TEST(bgp::get_plain_old_pointer(xp) != 0);
- typedef typename boost::generic_ptr::rebind
+ typedef typename bgp::rebind
<
GenericPointer,
- const typename boost::generic_ptr::pointer_traits<GenericPointer>::value_type
+ const typename bgp::pointer_traits<GenericPointer>::value_type
>::other pointer_to_const_x_type;
- pointer_to_const_x_type xp_const = boost::generic_ptr::const_pointer_cast
- <const typename boost::generic_ptr::pointer_traits<GenericPointer>::value_type>(p);
- xp = boost::generic_ptr::const_pointer_cast
+ pointer_to_const_x_type xp_const = bgp::const_pointer_cast
+ <const typename bgp::pointer_traits<GenericPointer>::value_type>(p);
+ xp = bgp::const_pointer_cast
<
- typename boost::generic_ptr::pointer_traits<GenericPointer>::value_type
+ typename bgp::pointer_traits<GenericPointer>::value_type
>(xp_const);
}
template<typename GenericPointer>
void conversion_to_base_test(GenericPointer &p, bool is_cloning_pointer = false)
{
- typedef typename boost::generic_ptr::rebind<GenericPointer, Y>::other pointer_to_base_type;
+ typedef typename bgp::rebind<GenericPointer, Y>::other pointer_to_base_type;
pointer_to_base_type base_p(p);
BOOST_TEST(p == base_p ||
is_cloning_pointer);
@@ -103,7 +105,7 @@
template<typename GenericPointer>
void conversion_to_void_test(GenericPointer &p, bool is_cloning_pointer = false)
{
- typedef typename boost::generic_ptr::rebind<GenericPointer, void>::other pointer_to_void_type;
+ typedef typename bgp::rebind<GenericPointer, void>::other pointer_to_void_type;
pointer_to_void_type void_p(p);
BOOST_TEST(p == void_p ||
is_cloning_pointer);
@@ -111,14 +113,14 @@
BOOST_TEST(p == void_p ||
is_cloning_pointer);
- typedef typename boost::generic_ptr::rebind
+ typedef typename bgp::rebind
<
GenericPointer,
- const typename boost::generic_ptr::pointer_traits<GenericPointer>::value_type
+ const typename bgp::pointer_traits<GenericPointer>::value_type
>::other pointer_to_const_type;
pointer_to_const_type cp(p);
- typedef typename boost::generic_ptr::rebind
+ typedef typename bgp::rebind
<
GenericPointer,
const void
@@ -131,6 +133,32 @@
is_cloning_pointer);
}
+#ifndef BOOST_NO_SFINAE
+template<typename GenericPointer>
+class overloaded
+{
+public:
+ typedef typename bgp::rebind<GenericPointer, Y>::other base_ptr;
+ typedef typename bgp::rebind<GenericPointer, int>::other other_ptr;
+ void f(const base_ptr &)
+ {
+ }
+ void f(const other_ptr &)
+ {
+ BOOST_TEST(false);
+ }
+};
+#endif // BOOST_NO_SFINAE
+
+template<typename GenericPointer>
+void overload_resolution_test(GenericPointer &p)
+{
+#ifndef BOOST_NO_SFINAE
+ overloaded<GenericPointer> o;
+ o.f(p);
+#endif // BOOST_NO_SFINAE
+}
+
int main()
{
{
@@ -140,74 +168,83 @@
cast_test(p);
conversion_to_base_test(p);
conversion_to_void_test(p);
+ overload_resolution_test(p);
}
{
X x;
- boost::generic_ptr::asserting<X*> p(&x);
+ bgp::asserting<X*> p(&x);
member_access_test(p);
dereference_test(p);
rebind_test(p);
cast_test(p);
conversion_to_base_test(p);
conversion_to_void_test(p);
+ overload_resolution_test(p);
}
{
X x;
- boost::generic_ptr::throwing<X*> p(&x);
+ bgp::throwing<X*> p(&x);
member_access_test(p);
dereference_test(p);
rebind_test(p);
cast_test(p);
conversion_to_base_test(p);
conversion_to_void_test(p);
+ overload_resolution_test(p);
}
{
X x;
- boost::generic_ptr::nonnull<X*> p(&x);
+ bgp::nonnull<X*> p(&x);
member_access_test(p);
dereference_test(p);
rebind_test(p);
cast_test(p);
conversion_to_base_test(p);
conversion_to_void_test(p);
+ overload_resolution_test(p);
}
{
X x;
- boost::generic_ptr::monitor<X*> p(&x);
+ bgp::monitor<X*> p(&x);
member_access_test(p);
// dereference_test(p); // monitors don't support dereference
rebind_test(p);
cast_test(p);
conversion_to_base_test(p);
conversion_to_void_test(p);
+ overload_resolution_test(p);
}
{
- boost::generic_ptr::shared<X*> p(new X());
+ bgp::shared<X*> p(new X());
member_access_test(p);
dereference_test(p);
rebind_test(p);
cast_test(p);
conversion_to_base_test(p);
conversion_to_void_test(p);
+ overload_resolution_test(p);
}
{
X x;
- boost::generic_ptr::intrusive<X*> p(&x);
+ bgp::intrusive<X*> p(&x);
member_access_test(p);
dereference_test(p);
rebind_test(p);
cast_test(p);
conversion_to_base_test(p);
// conversion_to_void_test(p); // intrusive doesn't support void pointers
+ overload_resolution_test(p);
}
{
- boost::generic_ptr::cloning<X*> p(new X());
+ bgp::cloning<X*> p(new X());
member_access_test(p);
dereference_test(p);
rebind_test(p);
cast_test(p);
conversion_to_base_test(p, true);
conversion_to_void_test(p, true);
+ overload_resolution_test(p);
}
+ //TODO: add tests for external pointer types
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk