cast: prefer concepts to SFINAE
This commit is contained in:
parent
c528e28a0e
commit
29e876c712
27
cast.hpp
27
cast.hpp
@ -34,12 +34,11 @@ namespace cruft::cast {
|
||||
typename T,
|
||||
typename U
|
||||
>
|
||||
std::enable_if_t<
|
||||
sizeof(T) == sizeof(U) &&
|
||||
requires
|
||||
(sizeof(T) == sizeof(U)) &&
|
||||
std::is_unsigned<T>::value &&
|
||||
std::is_signed<U>::value,
|
||||
std::is_signed<U>::value
|
||||
T
|
||||
>
|
||||
sign (const U u)
|
||||
{
|
||||
CHECK_GE (u, 0);
|
||||
@ -52,12 +51,11 @@ namespace cruft::cast {
|
||||
typename T,
|
||||
typename U
|
||||
>
|
||||
std::enable_if_t<
|
||||
sizeof(T) == sizeof (U) &&
|
||||
requires
|
||||
(sizeof(T) == sizeof (U)) &&
|
||||
std::is_signed<T>::value &&
|
||||
std::is_unsigned<U>::value,
|
||||
std::is_unsigned<U>::value
|
||||
T
|
||||
>
|
||||
sign (const U u)
|
||||
{
|
||||
CHECK_LT (u, std::numeric_limits<U>::max () / 2);
|
||||
@ -149,10 +147,10 @@ namespace cruft::cast {
|
||||
/// the converted value. Note: this is only a debug-time check and is
|
||||
/// compiled out in optimised builds.
|
||||
template <
|
||||
typename T,
|
||||
concepts::pointer T,
|
||||
typename V
|
||||
>
|
||||
std::enable_if_t<std::is_pointer_v<T>,T>
|
||||
T
|
||||
known (V *const v)
|
||||
{
|
||||
CHECK (dynamic_cast<T> (v));
|
||||
@ -162,10 +160,10 @@ namespace cruft::cast {
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <
|
||||
typename T,
|
||||
concepts::reference T,
|
||||
typename V
|
||||
>
|
||||
std::enable_if_t<std::is_reference_v<T>, T>
|
||||
T
|
||||
known (V &v)
|
||||
{
|
||||
CHECK_NOTHROW (dynamic_cast<T> (v));
|
||||
@ -179,9 +177,8 @@ namespace cruft::cast {
|
||||
///
|
||||
/// Runtime checks will be compiled out if NDEBUG is defined.
|
||||
template <
|
||||
typename DstT,
|
||||
typename SrcT,
|
||||
typename = std::enable_if_t<std::is_pointer_v<DstT> && std::is_pointer_v<SrcT>>
|
||||
concepts::pointer DstT,
|
||||
concepts::pointer SrcT
|
||||
>
|
||||
DstT
|
||||
alignment (SrcT src)
|
||||
|
Loading…
Reference in New Issue
Block a user