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