Fix is_base_of and is_base_and_derived to conform to C++0x.

Also fixed consistency of handling cv-qualified types.
Added new trait in boost::tr1 to archive old tr1 behaviour.
Updated TR1 lib to match.

[SVN r55404]
This commit is contained in:
John Maddock committed 2009-08-04 17:15:51 +00:00
1 parent 405c4ba902
commit c9e77b9c8d
6 files changed
+85 -7

No files matched your search

@@ -15,10 +15,10 @@
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/detail/ice_and.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/config.hpp>
#include <boost/static_assert.hpp>
#endif
#include <boost/type_traits/remove_cv.hpp>
// should be the last #include
#include <boost/type_traits/detail/bool_trait_def.hpp>
@@ -212,7 +212,7 @@ struct is_base_and_derived_impl
typedef is_base_and_derived_select<
::boost::is_class<B>::value,
::boost::is_class<D>::value,
::boost::is_same<B,D>::value> selector;
::boost::is_same<ncvB,ncvD>::value> selector;
typedef typename selector::template rebind<ncvB,ncvD> binder;
typedef typename binder::type bound_type;
@@ -222,7 +222,10 @@ struct is_base_and_derived_impl
template <typename B, typename D>
struct is_base_and_derived_impl
{
BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_BASE_OF(B,D));
typedef typename remove_cv<B>::type ncvB;
typedef typename remove_cv<D>::type ncvD;
BOOST_STATIC_CONSTANT(bool, value = (BOOST_IS_BASE_OF(B,D) && ! ::boost::is_same<ncvB,ncvD>::value));
};
#endif
} // namespace detail
+15 -4
View File
@@ -11,21 +11,32 @@
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/detail/ice_or.hpp>
#include <boost/type_traits/detail/ice_and.hpp>
// should be the last #include
#include <boost/type_traits/detail/bool_trait_def.hpp>
namespace boost {
namespace detail{
template <class B, class D>
struct is_base_of_imp
{
typedef typename remove_cv<B>::type ncvB;
typedef typename remove_cv<D>::type ncvD;
BOOST_STATIC_CONSTANT(bool, value = (::boost::type_traits::ice_or<
(::boost::detail::is_base_and_derived_impl<ncvB,ncvD>::value),
(::boost::type_traits::ice_and< ::boost::is_same<ncvB,ncvD>::value, ::boost::is_class<ncvB>::value>::value)>::value));
};
}
BOOST_TT_AUX_BOOL_TRAIT_DEF2(
is_base_of
, Base
, Derived
, (::boost::type_traits::ice_or<
(::boost::detail::is_base_and_derived_impl<Base,Derived>::value),
(::boost::is_same<Base,Derived>::value)>::value)
)
, (::boost::detail::is_base_of_imp<Base, Derived>::value))
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_base_of,Base&,Derived,false)
@@ -0,0 +1,50 @@
// (C) Copyright Rani Sharoni 2003-2005.
// Use, modification and distribution are subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt).
//
// See http://www.boost.org/libs/type_traits for most recent version including documentation.
#ifndef BOOST_TT_IS_BASE_OF_TR1_HPP_INCLUDED
#define BOOST_TT_IS_BASE_OF_TR1_HPP_INCLUDED
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/detail/ice_or.hpp>
// should be the last #include
#include <boost/type_traits/detail/bool_trait_def.hpp>
namespace boost { namespace tr1{
namespace detail{
template <class B, class D>
struct is_base_of_imp
{
typedef typename remove_cv<B>::type ncvB;
typedef typename remove_cv<D>::type ncvD;
BOOST_STATIC_CONSTANT(bool, value = (::boost::type_traits::ice_or<
(::boost::detail::is_base_and_derived_impl<ncvB,ncvD>::value),
(::boost::is_same<ncvB,ncvD>::value)>::value));
};
}
BOOST_TT_AUX_BOOL_TRAIT_DEF2(
is_base_of
, Base
, Derived
, (::boost::tr1::detail::is_base_of_imp<Base, Derived>::value))
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_base_of,Base&,Derived,false)
BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_base_of,Base,Derived&,false)
BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_base_of,Base&,Derived&,false)
#endif
} } // namespace boost
#include <boost/type_traits/detail/bool_trait_undef.hpp>
#endif // BOOST_TT_IS_BASE_OF_TR1_HPP_INCLUDED