blob: f49cd12904de495487d89d42c34ea22126425c24 [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001// (C) Copyright John Maddock 2000.
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_POLYMORPHIC_HPP
9#define BOOST_TT_IS_POLYMORPHIC_HPP
10
Jeff Thompson2277ce52013-08-01 17:34:11 -070011#include <ndnboost/type_traits/intrinsics.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070012#ifndef BOOST_IS_POLYMORPHIC
Jeff Thompson2277ce52013-08-01 17:34:11 -070013#include <ndnboost/type_traits/is_class.hpp>
14#include <ndnboost/type_traits/remove_cv.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070015#endif
16// should be the last #include
Jeff Thompson2277ce52013-08-01 17:34:11 -070017#include <ndnboost/type_traits/detail/bool_trait_def.hpp>
18#include <ndnboost/detail/workaround.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070019
20namespace ndnboost{
21
22#ifndef BOOST_IS_POLYMORPHIC
23
24namespace detail{
25
26template <class T>
27struct is_polymorphic_imp1
28{
29# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407) // CWPro7 should return false always.
30 typedef char d1, (&d2)[2];
31# else
32 typedef typename remove_cv<T>::type ncvT;
33 struct d1 : public ncvT
34 {
35 d1();
36# if !defined(__GNUC__) // this raises warnings with some classes, and buys nothing with GCC
37 ~d1()throw();
38# endif
39 char padding[256];
40 private:
41 // keep some picky compilers happy:
42 d1(const d1&);
43 d1& operator=(const d1&);
44 };
45 struct d2 : public ncvT
46 {
47 d2();
48 virtual ~d2()throw();
49# if !defined(BOOST_MSVC) && !defined(__ICL)
50 // for some reason this messes up VC++ when T has virtual bases,
51 // probably likewise for compilers that use the same ABI:
52 struct unique{};
53 virtual void unique_name_to_boost5487629(unique*);
54# endif
55 char padding[256];
56 private:
57 // keep some picky compilers happy:
58 d2(const d2&);
59 d2& operator=(const d2&);
60 };
61# endif
62 BOOST_STATIC_CONSTANT(bool, value = (sizeof(d2) == sizeof(d1)));
63};
64
65template <class T>
66struct is_polymorphic_imp2
67{
68 BOOST_STATIC_CONSTANT(bool, value = false);
69};
70
71template <bool is_class>
72struct is_polymorphic_selector
73{
74 template <class T>
75 struct rebind
76 {
77 typedef is_polymorphic_imp2<T> type;
78 };
79};
80
81template <>
82struct is_polymorphic_selector<true>
83{
84 template <class T>
85 struct rebind
86 {
87 typedef is_polymorphic_imp1<T> type;
88 };
89};
90
91template <class T>
92struct is_polymorphic_imp
93{
94 typedef is_polymorphic_selector< ::ndnboost::is_class<T>::value> selector;
95 typedef typename selector::template rebind<T> binder;
96 typedef typename binder::type imp_type;
97 BOOST_STATIC_CONSTANT(bool, value = imp_type::value);
98};
99
100} // namespace detail
101
102BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_polymorphic,T,::ndnboost::detail::is_polymorphic_imp<T>::value)
103
104#else // BOOST_IS_POLYMORPHIC
105
106BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_polymorphic,T,BOOST_IS_POLYMORPHIC(T))
107
108#endif
109
110} // namespace ndnboost
111
Jeff Thompson2277ce52013-08-01 17:34:11 -0700112#include <ndnboost/type_traits/detail/bool_trait_undef.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700113
114#endif