tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
bit_cast.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
3
#ifndef TETL_BIT_BIT_CAST_HPP
4
#define TETL_BIT_BIT_CAST_HPP
5
6
#include <
etl/_config/all.hpp
>
7
8
#include <
etl/_cstddef/size_t.hpp
>
9
#include <
etl/_strings/cstr.hpp
>
10
#include <
etl/_type_traits/is_trivially_constructible.hpp
>
11
#include <
etl/_type_traits/is_trivially_copyable.hpp
>
12
13
namespace
etl
{
14
15
namespace
detail {
16
17
template
<
typename
To,
typename
From>
18
concept
bitcastable = (
sizeof
(To) ==
sizeof
(From)) and
is_trivially_copyable_v<From>
and
is_trivially_copyable_v<To>
;
19
20
}
// namespace detail
21
36
template
<
typename
To,
typename
From>
37
requires
detail::bitcastable<To, From>
38
constexpr
auto
bit_cast
(From
const
& src)
noexcept
-> To
39
{
40
#if __has_builtin(__builtin_bit_cast) or (defined(_MSC_VER) and not defined(__clang__))
41
return
__builtin_bit_cast(To, src);
42
#else
43
To dst{};
44
etl::detail::memcpy<char, etl::size_t>(&dst, &src,
sizeof
(To));
45
return
dst;
46
#endif
47
}
48
49
}
// namespace etl
50
51
#endif
// TETL_BIT_BIT_CAST_HPP
all.hpp
cstr.hpp
etl::bit_cast
constexpr auto bit_cast(From const &src) noexcept -> To
Obtain a value of type To by reinterpreting the object representation of from. Every bit in the value...
Definition
bit_cast.hpp:38
is_trivially_constructible.hpp
is_trivially_copyable.hpp
etl
Definition
adjacent_find.hpp:8
etl::is_trivially_copyable_v
constexpr bool is_trivially_copyable_v
Definition
is_trivially_copyable.hpp:21
size_t.hpp
include
etl
_bit
bit_cast.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0