Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51754 - in trunk: boost/type_traits libs/type_traits/test
From: john_at_[hidden]
Date: 2009-03-13 13:55:21


Author: johnmaddock
Date: 2009-03-13 13:55:21 EDT (Fri, 13 Mar 2009)
New Revision: 51754
URL: http://svn.boost.org/trac/boost/changeset/51754

Log:
Add is_virtual_base_of.
Add extra tests for is_base_of to test virtual inheritance.
Trivial warning fix for is_abstract: fixes #2827.
Added:
   trunk/boost/type_traits/is_virtual_base_of.hpp (contents, props changed)
   trunk/libs/type_traits/test/is_virtual_base_of_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/type_traits/is_abstract.hpp | 4 ++--
   trunk/libs/type_traits/test/is_base_of_test.cpp | 2 ++
   trunk/libs/type_traits/test/test.hpp | 5 +++--
   3 files changed, 7 insertions(+), 4 deletions(-)

Modified: trunk/boost/type_traits/is_abstract.hpp
==============================================================================
--- trunk/boost/type_traits/is_abstract.hpp (original)
+++ trunk/boost/type_traits/is_abstract.hpp 2009-03-13 13:55:21 EDT (Fri, 13 Mar 2009)
@@ -92,13 +92,13 @@
    // GCC2 won't even parse this template if we embed the computation
    // of s1 in the computation of value.
 #ifdef __GNUC__
- BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(is_abstract_imp2<T>::template check_sig<T>(0)));
+ BOOST_STATIC_CONSTANT(std::size_t, s1 = sizeof(is_abstract_imp2<T>::template check_sig<T>(0)));
 #else
 #if BOOST_WORKAROUND(_MSC_FULL_VER, >= 140050000)
 #pragma warning(push)
 #pragma warning(disable:6334)
 #endif
- BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(check_sig<T>(0)));
+ BOOST_STATIC_CONSTANT(std::size_t, s1 = sizeof(check_sig<T>(0)));
 #if BOOST_WORKAROUND(_MSC_FULL_VER, >= 140050000)
 #pragma warning(pop)
 #endif

Added: trunk/boost/type_traits/is_virtual_base_of.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/type_traits/is_virtual_base_of.hpp 2009-03-13 13:55:21 EDT (Fri, 13 Mar 2009)
@@ -0,0 +1,87 @@
+// (C) Copyright Daniel Frey and Robert Ramey 2009.
+// 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_VIRTUAL_BASE_OF_HPP_INCLUDED
+#define BOOST_TT_IS_VIRTUAL_BASE_OF_HPP_INCLUDED
+
+#include <boost/type_traits/is_base_of.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/not.hpp>
+
+// should be the last #include
+#include <boost/type_traits/detail/bool_trait_def.hpp>
+
+namespace boost {
+namespace detail {
+
+
+#ifdef BOOST_MSVC
+#pragma warning( push )
+#pragma warning( disable : 4584 )
+#elif defined __GNUC__
+#pragma GCC system_header
+#endif
+
+template<typename Base, typename Derived, typename tag>
+struct is_virtual_base_of_impl
+{
+ BOOST_STATIC_CONSTANT(bool, value = false);
+};
+
+template<typename Base, typename Derived>
+struct is_virtual_base_of_impl<Base, Derived, mpl::true_>
+{
+ struct X : Derived, virtual Base
+ {
+ X();
+ X(const X&);
+ X& operator=(const X&);
+ ~X();
+ };
+ struct Y : Derived
+ {
+ Y();
+ Y(const Y&);
+ Y& operator=(const Y&);
+ ~Y();
+ };
+ BOOST_STATIC_CONSTANT(bool, value = sizeof(X)==sizeof(Y));
+};
+
+template<typename Base, typename Derived>
+struct is_virtual_base_of_impl2
+{
+ typedef typename mpl::and_<is_base_of<Base, Derived>, mpl::not_<is_same<Base, Derived> > >::type tag_type;
+ typedef is_virtual_base_of_impl<Base, Derived, tag_type> imp;
+ BOOST_STATIC_CONSTANT(bool, value = imp::value);
+};
+
+#ifdef BOOST_MSVC
+#pragma warning( pop )
+#endif
+
+} // namespace detail
+
+BOOST_TT_AUX_BOOL_TRAIT_DEF2(
+ is_virtual_base_of
+ , Base
+ , Derived
+ , (::boost::detail::is_virtual_base_of_impl2<Base,Derived>::value)
+)
+
+#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_virtual_base_of,Base&,Derived,false)
+BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_virtual_base_of,Base,Derived&,false)
+BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_virtual_base_of,Base&,Derived&,false)
+#endif
+
+} // namespace boost
+
+#include <boost/type_traits/detail/bool_trait_undef.hpp>
+
+#endif

Modified: trunk/libs/type_traits/test/is_base_of_test.cpp
==============================================================================
--- trunk/libs/type_traits/test/is_base_of_test.cpp (original)
+++ trunk/libs/type_traits/test/is_base_of_test.cpp 2009-03-13 13:55:21 EDT (Fri, 13 Mar 2009)
@@ -36,6 +36,8 @@
 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);
 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<test_abc3,test_abc1>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,virtual_inherit1>::value), true);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<virtual_inherit1,Base>::value), false);
 
 TT_TEST_END
 

Added: trunk/libs/type_traits/test/is_virtual_base_of_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/type_traits/test/is_virtual_base_of_test.cpp 2009-03-13 13:55:21 EDT (Fri, 13 Mar 2009)
@@ -0,0 +1,54 @@
+
+// (C) Copyright John Maddock 2009.
+// 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)
+
+
+#include "test.hpp"
+#include "check_integral_constant.hpp"
+#include <boost/type_traits/is_virtual_base_of.hpp>
+
+
+TT_TEST_BEGIN(is_virtual_base_of)
+
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Derived,Base>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Derived,Derived>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,Base>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,Derived>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,MultiBase>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Derived,MultiBase>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Derived2,MultiBase>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,PrivateBase>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<NonDerived,Base>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,void>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,const void>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<void,Derived>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<const void,Derived>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<int, int>::value), false); // really it is!!!!!
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<const int, int>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<VB,VD>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<VD,VB>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<test_abc1,test_abc3>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<test_abc3,test_abc1>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,virtual_inherit1>::value), true);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<virtual_inherit1,Base>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,virtual_inherit2>::value), true);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<virtual_inherit2,Base>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<Base,virtual_inherit3>::value), true);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<virtual_inherit3,Base>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<boost::noncopyable,virtual_inherit4>::value), true);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<virtual_inherit4,boost::noncopyable>::value), false);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<int_convertible,virtual_inherit5>::value), true);
+BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of<virtual_inherit5,int_convertible>::value), false);
+
+TT_TEST_END
+
+
+
+
+
+
+
+
+

Modified: trunk/libs/type_traits/test/test.hpp
==============================================================================
--- trunk/libs/type_traits/test/test.hpp (original)
+++ trunk/libs/type_traits/test/test.hpp 2009-03-13 13:55:21 EDT (Fri, 13 Mar 2009)
@@ -367,8 +367,9 @@
 
 struct virtual_inherit1 : virtual Base { };
 struct virtual_inherit2 : virtual_inherit1 { };
-
-
+struct virtual_inherit3 : private virtual Base {};
+struct virtual_inherit4 : private virtual boost::noncopyable {};
+struct virtual_inherit5 : private virtual int_convertible {};
 
 typedef void foo0_t();
 typedef void foo1_t(int);


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