add is_virtual_base_of trait

This commit is contained in:
BlackMATov
2023-03-03 21:22:21 +07:00
parent aa587c6c12
commit 3465e961f2
4 changed files with 151 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include "meta_base/insert_or_assign.hpp"
#include "meta_base/intrusive_ptr.hpp"
#include "meta_base/is_in_place_type.hpp"
#include "meta_base/is_virtual_base_of.hpp"
#include "meta_base/memory_buffer.hpp"
#include "meta_base/noncopyable.hpp"
#include "meta_base/nonesuch.hpp"

View File

@@ -0,0 +1,41 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "base.hpp"
namespace meta_hpp::detail
{
namespace impl
{
template < typename From, typename To >
constexpr bool is_virtual_base_of_impl(...) noexcept {
return false;
}
template <
typename From,
typename To,
decltype(static_cast<const volatile To*>(std::declval<const volatile From*>())) = nullptr >
constexpr bool is_virtual_base_of_impl(int) noexcept {
return true;
}
}
// clang-format off
template < typename Base, typename Derived >
struct is_virtual_base_of : std::integral_constant<bool,
std::is_base_of_v<Base, Derived> &&
impl::is_virtual_base_of_impl<Derived, Base>(0) &&
!impl::is_virtual_base_of_impl<Base, Derived>(0)> {};
// clang-format on
template < typename Base, typename Derived >
inline constexpr bool is_virtual_base_of_v = is_virtual_base_of<Base, Derived>::value;
}