halcheck
1.0
Loading...
Searching...
No Matches
include
halcheck
lib
bit.hpp
1
#ifndef HALCHECK_LIB_BIT_HPP
2
#define HALCHECK_LIB_BIT_HPP
3
11
#include <halcheck/lib/type_traits.hpp>
12
13
#include <
cstring
>
14
15
namespace
halcheck {
namespace
lib {
16
22
template
<
23
typename
T,
24
typename
U,
25
HALCHECK_REQUIRE
(
sizeof
(T) ==
sizeof
(U)),
26
HALCHECK_REQUIRE
(
std::is_trivially_copyable<T>
()),
27
HALCHECK_REQUIRE
(
std::is_trivially_copyable<U>
()),
28
HALCHECK_REQUIRE
(
std::is_trivially_constructible<T>
())>
29
T
bit_cast
(
const
U &src)
noexcept
{
30
T dest;
31
std::memcpy
(&dest, &src,
sizeof
(U));
32
return
dest;
33
}
34
35
}}
// namespace halcheck::lib
36
37
#endif
cstring
halcheck::lib::bit_cast
T bit_cast(const U &src) noexcept
Performs a bit-level conversion from one type to another.
Definition
bit.hpp:29
HALCHECK_REQUIRE
#define HALCHECK_REQUIRE(...)
Expands to a template argument that is only valid if the given argument evaluates to true.
Definition
type_traits.hpp:24
std::is_trivially_constructible
std::is_trivially_copyable
std::memcpy
T memcpy(T... args)
Generated by
1.12.0