mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::util: Add sign cast convenience suite.
This commit is contained in:
parent
ef930635de
commit
b1c2576c20
1 changed files with 28 additions and 0 deletions
|
@ -140,6 +140,34 @@ struct is_specialization_of<T<args...>, T>
|
||||||
:std::true_type
|
:std::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Convenience signedness cast template
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
using enable_if_s2u = std::enable_if<std::is_signed<T>::value, typename std::make_unsigned<T>::type>;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
[[using gnu: always_inline, gnu_inline, artificial]]
|
||||||
|
extern inline typename enable_if_s2u<T>::type *
|
||||||
|
sign_cast(T *const t)
|
||||||
|
{
|
||||||
|
using type = typename std::make_unsigned<T>::type;
|
||||||
|
return reinterpret_cast<type *>(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
using enable_if_u2s = std::enable_if<std::is_unsigned<T>::value, typename std::make_signed<T>::type>;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
[[using gnu: always_inline, gnu_inline, artificial]]
|
||||||
|
extern inline typename enable_if_u2s<T>::type *
|
||||||
|
sign_cast(T *const t)
|
||||||
|
{
|
||||||
|
using type = typename std::make_signed<T>::type;
|
||||||
|
return reinterpret_cast<type *>(t);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Convenience const_cast deduction template
|
// Convenience const_cast deduction template
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue