Reinterpret the object representation of from as type To.
Declared in <llvm/ADT/bit.h>
template<
typename To,
typename From>
requires sizeof(To) == sizeof(From) && std::is_trivially_constructible<To>::value && std::is_trivially_copyable<To>::value && std::is_trivially_copyable<From>::value
[[nodiscard]]
To
bit_cast(From const& from) noexcept;
This implementation of bit_cast is different from the C++20 one in two ways:
It isn't constexpr because that requires compiler support.
It requires trivially-constructible To, to avoid UB in the implementation.
Value of type To with the same object representation as from.
The return value should not be discarded.
| Name | Description |
|---|---|
| from | Object whose representation is reinterpreted as To. |