]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/is_polymorphic.hpp
Bug: 935
[lyx.git] / boost / boost / type_traits / is_polymorphic.hpp
1 //  (C) Copyright John Maddock 2000. Permission to copy, use, modify, sell and   
2 //  distribute this software is granted provided this copyright notice appears
3 //  in all copies. This software is provided "as is" without express or implied
4 //  warranty, and with no claim as to its suitability for any purpose.
5
6 #ifndef BOOST_TT_IS_POLYMORPHIC_HPP
7 #define BOOST_TT_IS_POLYMORPHIC_HPP
8
9 #include <boost/type_traits/is_class.hpp>
10 #include <boost/type_traits/remove_cv.hpp>
11 // should be the last #include
12 #include "boost/type_traits/detail/bool_trait_def.hpp"
13 #include <boost/detail/workaround.hpp>
14
15 namespace boost{
16 namespace detail{
17
18 template <class T>
19 struct is_polymorphic_imp1
20 {
21 # if BOOST_WORKAROUND(__MWERKS__, <= 0x2407) // CWPro7 should return false always.
22     typedef char d1, (&d2)[2];
23 # else 
24    typedef typename remove_cv<T>::type ncvT;
25    struct d1 : public ncvT
26    {
27       d1();
28 #  if !defined(__GNUC__) // this raises warnings with some classes, and buys nothing with GCC
29       ~d1()throw();
30 #  endif 
31       char padding[256];
32    };
33    struct d2 : public ncvT
34    {
35       d2();
36       virtual ~d2()throw();
37 #  ifndef BOOST_MSVC
38       // for some reason this messes up VC++ when T has virtual bases:
39       virtual void foo();
40 #  endif
41       char padding[256];
42    };
43 # endif 
44    BOOST_STATIC_CONSTANT(bool, value = (sizeof(d2) == sizeof(d1)));
45 };
46
47 template <class T>
48 struct is_polymorphic_imp2
49 {
50    BOOST_STATIC_CONSTANT(bool, value = false);
51 };
52
53 template <bool is_class>
54 struct is_polymorphic_selector
55 {
56    template <class T>
57    struct rebind
58    {
59       typedef is_polymorphic_imp2<T> type;
60    };
61 };
62
63 template <>
64 struct is_polymorphic_selector<true>
65 {
66    template <class T>
67    struct rebind
68    {
69       typedef is_polymorphic_imp1<T> type;
70    };
71 };
72
73 template <class T>
74 struct is_polymorphic_imp
75 {
76    typedef is_polymorphic_selector< ::boost::is_class<T>::value> selector;
77    typedef typename selector::template rebind<T> binder;
78    typedef typename binder::type imp_type;
79    BOOST_STATIC_CONSTANT(bool, value = imp_type::value);
80 };
81
82 } // namespace detail
83
84 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_polymorphic,T,::boost::detail::is_polymorphic_imp<T>::value)
85
86 } // namespace boost
87
88 #include "boost/type_traits/detail/bool_trait_undef.hpp"
89
90 #endif