forked from boostorg/type_traits
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:
@@ -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
|
||||
|
19
include/boost/type_traits/is_base_of.hpp
Executable file → Normal file
19
include/boost/type_traits/is_base_of.hpp
Executable file → Normal 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)
|
||||
|
50
include/boost/type_traits/is_base_of_tr1.hpp
Normal file
50
include/boost/type_traits/is_base_of_tr1.hpp
Normal file
@@ -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
|
@@ -41,8 +41,13 @@ BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Base,void>::value), fal
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Base,const void>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<void,Derived>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<const void,Derived>::value), false);
|
||||
#if defined(TEST_STD) && (TEST_STD < 2006)
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<int, int>::value), true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<const int, int>::value), true);
|
||||
#else
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<int, int>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<const int, int>::value), false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<VB,VD>::value), true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<VD,VB>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<test_abc1,test_abc3>::value), true);
|
||||
|
@@ -33,8 +33,13 @@ BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,void>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,const void>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<void,Derived>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<const void,Derived>::value), false);
|
||||
#if defined(TEST_STD) && (TEST_STD < 2006)
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<int, int>::value), true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<const int, int>::value), true);
|
||||
#else
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<int, int>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<const int, int>::value), false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<VB,VD>::value), true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<VD,VB>::value), false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<test_abc1,test_abc3>::value), true);
|
||||
|
@@ -39,7 +39,11 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<foo0_t>::value, fals
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<foo0_t>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<foo0_t>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<foo0_t>::value, false);
|
||||
#if defined(TEST_STD) && (TEST_STD < 2006)
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<foo0_t, foo0_t>::value), true); // TR1 required behaviour (new to 1.34)
|
||||
#else
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<foo0_t, foo0_t>::value), false); // C++0x required behaviour (new to 1.40)
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible<foo0_t, int>::value), false);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user