latest from svn
[boost:type_traits.git] / include / boost / type_traits / is_virtual_base_of.hpp
1 //  (C) Copyright Daniel Frey and Robert Ramey 2009.
2 //  Use, modification and distribution are subject to the Boost Software License,
3 //  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 //  http://www.boost.org/LICENSE_1_0.txt).
5 //
6 //  See http://www.boost.org/libs/type_traits for most recent version including documentation.
7  
8 #ifndef BOOST_TT_IS_VIRTUAL_BASE_OF_HPP_INCLUDED
9 #define BOOST_TT_IS_VIRTUAL_BASE_OF_HPP_INCLUDED
10
11 #include <boost/type_traits/is_base_of.hpp>
12 #include <boost/type_traits/is_same.hpp>
13 #include <boost/mpl/and.hpp>
14 #include <boost/mpl/not.hpp>
15
16 // should be the last #include
17 #include <boost/type_traits/detail/bool_trait_def.hpp>
18
19 namespace boost {
20 namespace detail {
21
22
23 #ifdef BOOST_MSVC
24 #pragma warning( push )
25 #pragma warning( disable : 4584 )
26 #elif defined __GNUC__
27 #pragma GCC system_header
28 #endif
29
30 template<typename Base, typename Derived, typename tag>
31 struct is_virtual_base_of_impl
32 {
33     BOOST_STATIC_CONSTANT(bool, value = false);
34 };
35
36 template<typename Base, typename Derived>
37 struct is_virtual_base_of_impl<Base, Derived, mpl::true_>
38 {
39 #ifdef __BORLANDC__
40     struct boost_type_traits_internal_struct_X : public virtual Derived, public virtual Base 
41     {
42        boost_type_traits_internal_struct_X();
43        boost_type_traits_internal_struct_X(const boost_type_traits_internal_struct_X&);
44        boost_type_traits_internal_struct_X& operator=(const boost_type_traits_internal_struct_X&);
45        ~boost_type_traits_internal_struct_X()throw();
46     };
47     struct boost_type_traits_internal_struct_Y : public virtual Derived 
48     {
49        boost_type_traits_internal_struct_Y();
50        boost_type_traits_internal_struct_Y(const boost_type_traits_internal_struct_Y&);
51        boost_type_traits_internal_struct_Y& operator=(const boost_type_traits_internal_struct_Y&);
52        ~boost_type_traits_internal_struct_Y()throw();
53     };
54 #else
55     struct boost_type_traits_internal_struct_X : Derived, virtual Base 
56     {
57        boost_type_traits_internal_struct_X();
58        boost_type_traits_internal_struct_X(const boost_type_traits_internal_struct_X&);
59        boost_type_traits_internal_struct_X& operator=(const boost_type_traits_internal_struct_X&);
60        ~boost_type_traits_internal_struct_X()throw();
61     };
62     struct boost_type_traits_internal_struct_Y : Derived 
63     {
64        boost_type_traits_internal_struct_Y();
65        boost_type_traits_internal_struct_Y(const boost_type_traits_internal_struct_Y&);
66        boost_type_traits_internal_struct_Y& operator=(const boost_type_traits_internal_struct_Y&);
67        ~boost_type_traits_internal_struct_Y()throw();
68     };
69 #endif
70     BOOST_STATIC_CONSTANT(bool, value = (sizeof(boost_type_traits_internal_struct_X)==sizeof(boost_type_traits_internal_struct_Y)));
71 };
72
73 template<typename Base, typename Derived>
74 struct is_virtual_base_of_impl2
75 {
76    typedef typename mpl::and_<is_base_of<Base, Derived>, mpl::not_<is_same<Base, Derived> > >::type tag_type;
77    typedef is_virtual_base_of_impl<Base, Derived, tag_type> imp;
78    BOOST_STATIC_CONSTANT(bool, value = imp::value);
79 };
80
81 #ifdef BOOST_MSVC
82 #pragma warning( pop )
83 #endif
84
85 } // namespace detail
86
87 BOOST_TT_AUX_BOOL_TRAIT_DEF2(
88       is_virtual_base_of
89        , Base
90        , Derived
91        , (::boost::detail::is_virtual_base_of_impl2<Base,Derived>::value) 
92 )
93
94 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
95 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_virtual_base_of,Base&,Derived,false)
96 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_virtual_base_of,Base,Derived&,false)
97 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_virtual_base_of,Base&,Derived&,false)
98 #endif
99
100 } // namespace boost
101
102 #include <boost/type_traits/detail/bool_trait_undef.hpp>
103
104 #endif