halcheck 1.0
Loading...
Searching...
No Matches
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
15namespace halcheck { namespace lib {
16
22template<
23 typename T,
24 typename U,
25 HALCHECK_REQUIRE(sizeof(T) == sizeof(U)),
29T 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
T bit_cast(const U &src) noexcept
Performs a bit-level conversion from one type to another.
Definition bit.hpp:29
#define HALCHECK_REQUIRE(...)
Expands to a template argument that is only valid if the given argument evaluates to true.
Definition type_traits.hpp:24
T memcpy(T... args)