]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/type_traits/is_virtual_base_of.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / type_traits / is_virtual_base_of.hpp
CommitLineData
7c673cae 1// (C) Copyright Daniel Frey and Robert Ramey 2009.
92f5a8d4 2// (C) Copyright Balint Cserni 2017
7c673cae
FG
3// Use, modification and distribution are subject to the Boost Software License,
4// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt).
6//
7// See http://www.boost.org/libs/type_traits for most recent version including documentation.
8
9#ifndef BOOST_TT_IS_VIRTUAL_BASE_OF_HPP_INCLUDED
10#define BOOST_TT_IS_VIRTUAL_BASE_OF_HPP_INCLUDED
11
12#include <boost/type_traits/is_base_of.hpp>
13#include <boost/type_traits/is_same.hpp>
92f5a8d4
TL
14#include <boost/type_traits/make_void.hpp>
15#include <utility>
7c673cae
FG
16
17namespace boost {
92f5a8d4 18 namespace detail {
7c673cae
FG
19
20
21#ifdef BOOST_MSVC
22#pragma warning( push )
23#pragma warning( disable : 4584 4250 4594)
24#elif defined(__GNUC__) && (__GNUC__ >= 4)
25#pragma GCC system_header
26#endif
27
92f5a8d4 28#if !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) && !defined(BOOST_NO_CXX11_NULLPTR) && !BOOST_WORKAROUND(BOOST_GCC, < 40800)
7c673cae 29
92f5a8d4
TL
30 // Implementation based on the standard's rules of explicit type conversions.
31 // A pointer to an object of *derived* class type may be explicitly converted to a pointer to an *unambiguous* *base* class type.
32 // A pointer to an object of an *unambiguous* *non-virtual* *base* class type may be explicitly converted to a pointer of a *derived* class type.
33 // Therefore Derived has a virtual base Base if and only if
34 // (1) a Derived* can be converted to Base* (so the base class is unambiguous, which comes necessarily from virtual inheritance)
35 // (2) a Base* cannot be converted to Derived* (so the base class is either ambiguous or virtual)
36 // With both conditions true, Base must be a virtual base of Derived.
37 // The "is_base_of" is only needed so the compiler can (but is not required to) error out if the types are incomplete.
38 // This is in league with the the expected behaviour.
39
40 template<class T, class U>
41 constexpr bool is_virtual_base_impl(...) { return true; }
42
43 // C-style casts have the power to ignore inheritance visibility while still act as a static_cast.
44 // They can also fall back to the behaviour of reinterpret_cast, which allows is_virtual_base_of to work on non-class types too.
45 // Note that because we are casting pointers there can be no user-defined operators to interfere.
46 template<class T, class U,
47 typename boost::make_void<decltype((U*)(std::declval<T*>()))>::type* =
48 nullptr>
49 constexpr bool is_virtual_base_impl(int) { return false; }
50
51 } // namespace detail
52
53 template<class T, class U>
54 struct is_virtual_base_of : public
55 boost::integral_constant<
56 bool,
57 boost::is_base_of<T, U>::value &&
58 detail::is_virtual_base_impl<T, U>(0) &&
59 !detail::is_virtual_base_impl<U, T>(0)
60 > {};
61
62#else
63
64 template<typename Base, typename Derived, typename tag>
65 struct is_virtual_base_of_impl
66 {
67 BOOST_STATIC_CONSTANT(bool, value = false);
68 };
69
70 template<typename Base, typename Derived>
71 struct is_virtual_base_of_impl<Base, Derived, true_type>
7c673cae 72 {
92f5a8d4
TL
73 union max_align
74 {
75 unsigned u;
76 unsigned long ul;
77 void* v;
78 double d;
79 long double ld;
7c673cae 80#ifndef BOOST_NO_LONG_LONG
92f5a8d4 81 long long ll;
7c673cae 82#endif
92f5a8d4 83 };
20effc67 84#ifdef BOOST_BORLANDC
92f5a8d4
TL
85 struct boost_type_traits_internal_struct_X : public virtual Derived, public virtual Base
86 {
87 boost_type_traits_internal_struct_X();
88 boost_type_traits_internal_struct_X(const boost_type_traits_internal_struct_X&);
89 boost_type_traits_internal_struct_X& operator=(const boost_type_traits_internal_struct_X&);
90 ~boost_type_traits_internal_struct_X()throw();
91 max_align data[4];
92 };
93 struct boost_type_traits_internal_struct_Y : public virtual Derived
94 {
95 boost_type_traits_internal_struct_Y();
96 boost_type_traits_internal_struct_Y(const boost_type_traits_internal_struct_Y&);
97 boost_type_traits_internal_struct_Y& operator=(const boost_type_traits_internal_struct_Y&);
98 ~boost_type_traits_internal_struct_Y()throw();
99 max_align data[4];
100 };
7c673cae 101#else
92f5a8d4
TL
102 struct boost_type_traits_internal_struct_X : public Derived, virtual Base
103 {
104 boost_type_traits_internal_struct_X();
105 boost_type_traits_internal_struct_X(const boost_type_traits_internal_struct_X&);
106 boost_type_traits_internal_struct_X& operator=(const boost_type_traits_internal_struct_X&);
107 ~boost_type_traits_internal_struct_X()throw();
108 max_align data[16];
109 };
110 struct boost_type_traits_internal_struct_Y : public Derived
111 {
112 boost_type_traits_internal_struct_Y();
113 boost_type_traits_internal_struct_Y(const boost_type_traits_internal_struct_Y&);
114 boost_type_traits_internal_struct_Y& operator=(const boost_type_traits_internal_struct_Y&);
115 ~boost_type_traits_internal_struct_Y()throw();
116 max_align data[16];
117 };
7c673cae 118#endif
92f5a8d4
TL
119 BOOST_STATIC_CONSTANT(bool, value = (sizeof(boost_type_traits_internal_struct_X) == sizeof(boost_type_traits_internal_struct_Y)));
120 };
7c673cae 121
92f5a8d4
TL
122 template<typename Base, typename Derived>
123 struct is_virtual_base_of_impl2
124 {
125 typedef boost::integral_constant<bool, (boost::is_base_of<Base, Derived>::value && !boost::is_same<Base, Derived>::value)> tag_type;
126 typedef is_virtual_base_of_impl<Base, Derived, tag_type> imp;
127 BOOST_STATIC_CONSTANT(bool, value = imp::value);
128 };
7c673cae
FG
129
130} // namespace detail
131
92f5a8d4
TL
132template <class Base, class Derived> struct is_virtual_base_of : public integral_constant<bool, (::boost::detail::is_virtual_base_of_impl2<Base, Derived>::value)> {};
133
134#endif
7c673cae
FG
135
136template <class Base, class Derived> struct is_virtual_base_of<Base&, Derived> : public false_type{};
137template <class Base, class Derived> struct is_virtual_base_of<Base, Derived&> : public false_type{};
138template <class Base, class Derived> struct is_virtual_base_of<Base&, Derived&> : public false_type{};
139
92f5a8d4
TL
140#ifdef BOOST_MSVC
141#pragma warning( pop )
142#endif
143
7c673cae
FG
144} // namespace boost
145
146#endif