cast: disable invalid overloads of known
using sfinae
This commit is contained in:
parent
2bbe6dc900
commit
b510c48797
22
cast.hpp
22
cast.hpp
@ -127,22 +127,28 @@ namespace cruft::cast {
|
||||
/// assert if the value is not a pointer to a subclass of T, else return
|
||||
/// the converted value. Note: this is only a debug-time check and is
|
||||
/// compiled out in optimised builds.
|
||||
template <typename T, typename V>
|
||||
T*
|
||||
known (V *v)
|
||||
template <
|
||||
typename T,
|
||||
typename V
|
||||
>
|
||||
std::enable_if_t<std::is_pointer_v<T>,T>
|
||||
known (V *const v)
|
||||
{
|
||||
CHECK (dynamic_cast<T*> (v));
|
||||
return static_cast<T*> (v);
|
||||
CHECK (dynamic_cast<T> (v));
|
||||
return static_cast<T> (v);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename T, typename V>
|
||||
T&
|
||||
template <
|
||||
typename T,
|
||||
typename V
|
||||
>
|
||||
std::enable_if_t<std::is_reference_v<T>, T>
|
||||
known (V &v)
|
||||
{
|
||||
CHECK_NOTHROW (dynamic_cast<T> (v));
|
||||
return static_cast<T> (v);
|
||||
return reinterpret_cast<T> (v);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user