Skip to content

Commit c82500b

Browse files
committed
feat: add MEM_ZERO and BITS_TO_VALUE
1 parent 9f05bd7 commit c82500b

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

include/REX/REX/CAST.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ namespace REX
2525
reinterpret_cast<std::uintptr_t*>(a_ptr)[0] = T::VTABLE[0].address();
2626
}
2727

28+
template <class T>
29+
void MEM_ZERO(volatile T* a_ptr, std::size_t a_size = sizeof(T))
30+
{
31+
std::fill_n(reinterpret_cast<volatile char*>(a_ptr), a_size, '\0');
32+
}
33+
2834
template <class T1, class T2>
2935
[[nodiscard]] T1 UNRESTRICTED_CAST(T2 a_from)
3036
{

include/REX/REX/CONVERT.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55

66
namespace REX
77
{
8+
template <class U, class... T>
9+
U BITS_TO_VALUE(T... a_args)
10+
requires(std::same_as<std::remove_cv_t<T>, bool> && ...)
11+
{
12+
constexpr auto ARGC = sizeof...(T);
13+
14+
std::bitset<ARGC> bits;
15+
std::size_t i = 0;
16+
((bits[i++] = a_args), ...);
17+
18+
if constexpr (ARGC <= std::numeric_limits<std::uint32_t>::digits) {
19+
static_cast<U>(return bits.to_ulong());
20+
} else if constexpr (ARGC <= std::numeric_limits<std::uint64_t>::digits) {
21+
static_cast<U>(return bits.to_ullong());
22+
} else {
23+
static_assert(false && sizeof...(T));
24+
}
25+
}
26+
827
inline bool UTF8_TO_UTF16(const std::string_view a_in, std::wstring& a_out) noexcept
928
{
1029
const auto cvt = [&](wchar_t* a_dst, std::size_t a_length) {

0 commit comments

Comments
 (0)