Sen API
Sen Libraries
Loading...
Searching...
No Matches
bits.h
Go to the documentation of this file.
1
// === bits.h ==========================================================================================================
2
// Sen Infrastructure
3
// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4
// See the LICENSE.txt file for more information.
5
// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6
// =====================================================================================================================
7
8
#ifndef SEN_CORE_BASE_BITS_H
9
#define SEN_CORE_BASE_BITS_H
10
11
#if defined(__cpp_lib_bit_cast)
12
# include <bit>
13
#endif
14
15
// std
16
#include <cstring>
17
#include <type_traits>
18
19
#if defined(__cpp_lib_bit_cast)
20
namespace
sen::std_util
21
{
22
using
std::bit_cast;
23
}
// namespace sen::std_util
24
#else
25
namespace
sen::std_util
26
{
27
28
// Forward implementation of std::bit_cast from C++20.
29
// Impl provided by: https://en.cppreference.com/w/cpp/numeric/bit_cast.html
30
template
<
class
To,
class
From>
31
std::enable_if_t<
sizeof
(To) ==
sizeof
(From) && std::is_trivially_copyable_v<From> && std::is_trivially_copyable_v<To>,
32
To>
33
// NOLINTNEXTLINE(readability-identifier-naming): name defined by std
34
bit_cast
(
const
From& src)
noexcept
35
{
36
static_assert
(std::is_trivially_constructible_v<To>,
37
"This implementation additionally requires "
38
"destination type to be trivially constructible"
);
39
40
To dst;
41
std::memcpy(&dst, &src,
sizeof
(To));
42
return
dst;
43
}
44
45
}
// namespace sen::std_util
46
#endif
47
48
#endif
// SEN_CORE_BASE_BITS_H
sen::std_util
Definition
bits.h:26
sen::std_util::bit_cast
std::enable_if_t< sizeof(To)==sizeof(From) &&std::is_trivially_copyable_v< From > &&std::is_trivially_copyable_v< To >, To > bit_cast(const From &src) noexcept
Definition
bits.h:34
libs
core
include
sen
core
base
bits.h
Generated by
1.16.1