| 1 | #ifndef BOOST_DESCRIBE_DETAIL_COMPUTE_BASE_MODIFIERS_HPP_INCLUDED |
| 2 | #define BOOST_DESCRIBE_DETAIL_COMPUTE_BASE_MODIFIERS_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright 2020, 2021 Peter Dimov |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // https://www.boost.org/LICENSE_1_0.txt |
| 7 | |
| 8 | #include <boost/describe/modifiers.hpp> |
| 9 | #include <type_traits> |
| 10 | |
| 11 | namespace boost |
| 12 | { |
| 13 | namespace describe |
| 14 | { |
| 15 | namespace detail |
| 16 | { |
| 17 | |
| 18 | #if defined(_MSC_VER) |
| 19 | # pragma warning(push) |
| 20 | # pragma warning(disable: 4594) // can never be instantiated - indirect virtual base class is inaccessible |
| 21 | # pragma warning(disable: 4624) // destructor was implicitly defined as deleted |
| 22 | #endif |
| 23 | |
| 24 | // is_public_base_of |
| 25 | |
| 26 | template<class T, class U> using is_public_base_of = std::is_convertible<U*, T*>; |
| 27 | |
| 28 | // is_protected_base_of |
| 29 | |
| 30 | struct ipb_final |
| 31 | { |
| 32 | template<class T, class U> using fn = std::false_type; |
| 33 | }; |
| 34 | |
| 35 | struct ipb_non_final |
| 36 | { |
| 37 | template<class T, class U> struct fn: U |
| 38 | { |
| 39 | static std::true_type f( T* ); |
| 40 | |
| 41 | template<class X> static auto g( X x ) -> decltype( f(x) ); |
| 42 | static std::false_type g( ... ); |
| 43 | |
| 44 | using type = decltype( g((U*)0) ); |
| 45 | }; |
| 46 | }; |
| 47 | |
| 48 | template<class T, class U> using is_protected_base_of = |
| 49 | typename std::conditional<std::is_final<U>::value || std::is_union<U>::value, ipb_final, ipb_non_final>::type::template fn<T, U>::type; |
| 50 | |
| 51 | // is_virtual_base_of |
| 52 | |
| 53 | template<class T, class U, class = void> struct can_cast: std::false_type {}; |
| 54 | template<class T, class U> struct can_cast<T, U, decltype((void)(U*)(T*)0)>: std::true_type {}; |
| 55 | |
| 56 | template<class T, class U> using is_virtual_base_of = |
| 57 | std::integral_constant<bool, can_cast<U, T>::value && !can_cast<T, U>::value>; |
| 58 | |
| 59 | // compute_base_modifiers |
| 60 | template<class C, class B> constexpr unsigned compute_base_modifiers() noexcept |
| 61 | { |
| 62 | return (is_public_base_of<B, C>::value? mod_public: (is_protected_base_of<B, C>::value? mod_protected: mod_private)) | (is_virtual_base_of<B, C>::value? mod_virtual: 0); |
| 63 | } |
| 64 | |
| 65 | #if defined(_MSC_VER) |
| 66 | # pragma warning(pop) |
| 67 | #endif |
| 68 | |
| 69 | } // namespace detail |
| 70 | } // namespace describe |
| 71 | } // namespace boost |
| 72 | |
| 73 | #endif // #ifndef BOOST_DESCRIBE_DETAIL_COMPUTE_BASE_MODIFIERS_HPP_INCLUDED |
| 74 | |