llvm::bit_cast

Reinterpret the object representation of from as type To.

Synopsis

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;

Description

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.

Return Value

Value of type To with the same object representation as from.

NOTE

The return value should not be discarded.

Parameters

NameDescription
fromObject whose representation is reinterpreted as To.