mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
types.hpp: add PtrCastable concept
This commit is contained in:
parent
d81a5b1423
commit
eec9578619
2 changed files with 10 additions and 9 deletions
|
@ -25,12 +25,6 @@ namespace stx
|
||||||
static thread_local const
|
static thread_local const
|
||||||
#endif
|
#endif
|
||||||
fake_t<std::remove_cv_t<T>> sample{};
|
fake_t<std::remove_cv_t<T>> sample{};
|
||||||
|
|
||||||
template <typename From, typename To, typename = void>
|
|
||||||
struct can_static_cast : std::false_type {};
|
|
||||||
|
|
||||||
template <typename From, typename To>
|
|
||||||
struct can_static_cast<From, To, std::void_t<decltype(static_cast<To>(std::declval<From>()))>> : std::true_type {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Classify compile-time information available for pointers
|
// Classify compile-time information available for pointers
|
||||||
|
@ -55,13 +49,13 @@ namespace stx
|
||||||
{
|
{
|
||||||
return same_ptr::yes;
|
return same_ptr::yes;
|
||||||
}
|
}
|
||||||
else if constexpr (detail::can_static_cast<U*, T*>::value && !std::is_abstract_v<U>)
|
else if constexpr (PtrCastable<T, U> && !std::is_abstract_v<U>)
|
||||||
{
|
{
|
||||||
return is_same_ptr_test<T, U>() ? same_ptr::yes : same_ptr::no;
|
return is_same_ptr_test<T, U>() ? same_ptr::yes : same_ptr::no;
|
||||||
}
|
}
|
||||||
else if constexpr (detail::can_static_cast<T*, U*>::value && !std::is_abstract_v<T>)
|
else if constexpr (PtrCastable<T, U> && !std::is_abstract_v<T>)
|
||||||
{
|
{
|
||||||
return is_same_ptr_test<U, T>() ? same_ptr::yes : same_ptr::no;
|
return is_same_ptr_test<T, U>() ? same_ptr::yes : same_ptr::no;
|
||||||
}
|
}
|
||||||
|
|
||||||
return same_ptr::maybe;
|
return same_ptr::maybe;
|
||||||
|
|
|
@ -1010,3 +1010,10 @@ constexpr auto fill_array(const T&... args)
|
||||||
{
|
{
|
||||||
return fill_array_t<T...>{{args...}};
|
return fill_array_t<T...>{{args...}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename X, typename Y>
|
||||||
|
concept PtrCastable = requires(const volatile X* x, const volatile Y* y)
|
||||||
|
{
|
||||||
|
static_cast<const volatile Y*>(x);
|
||||||
|
static_cast<const volatile X*>(y);
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue