Fixed is_base_and_derived to work correctly with non-class types.

Moved to object_traits.hpp from conversion_traits.hpp


[SVN r12353]
This commit is contained in:
John Maddock
2002-01-19 13:00:45 +00:00
parent b57557b3c3
commit 77c0127cc6
2 changed files with 33 additions and 35 deletions

View File

@ -25,6 +25,9 @@
#ifndef BOOST_ARITHMETIC_TYPE_TRAITS_HPP
#include <boost/type_traits/arithmetic_traits.hpp>
#endif
#ifndef BOOST_SAME_TRAITS_HPP
#include <boost/type_traits/same_traits.hpp>
#endif
//
// is one type convertable to another?
//
@ -230,41 +233,6 @@ struct is_convertible<void, void>
#endif // is_convertible
template <class Base, class Derived>
struct is_base_and_derived
{
BOOST_STATIC_CONSTANT(bool, value =
(::boost::type_traits::ice_and<
::boost::is_convertible<Derived*,Base*>::value,
::boost::type_traits::ice_not<
::boost::is_void<Base>::value
>::value
>::value)
);
};
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Base, class Derived>
struct is_base_and_derived<Base&, Derived>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class Base, class Derived>
struct is_base_and_derived<Base, Derived&>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class Base, class Derived>
struct is_base_and_derived<Base&, Derived&>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class Base>
struct is_base_and_derived<Base, void>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
#endif
} // namespace boost

View File

@ -380,6 +380,36 @@ template <typename T> struct is_empty
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Base, class Derived>
struct is_base_and_derived
{
BOOST_STATIC_CONSTANT(bool, value =
(::boost::type_traits::ice_and<
::boost::is_convertible<Derived*,Base*>::value,
::boost::is_class<Derived>::value,
::boost::is_class<Base>::value
>::value)
);
};
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Base, class Derived>
struct is_base_and_derived<Base&, Derived>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class Base, class Derived>
struct is_base_and_derived<Base, Derived&>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class Base, class Derived>
struct is_base_and_derived<Base&, Derived&>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
#endif
} // namespace boost
#endif // BOOST_OBJECT_TYPE_TRAITS_HPP