Namespaces
Variants
Views
Actions

std::bit_cast

From cppreference.com
< cpp‎ | numeric
Defined in header <bit>
template< class To, class From >
constexpr To bit_cast(const From& from) noexcept;
(since C++20)

Obtain a value of type To by reinterpreting the object representation of from. Every bit in the value representation of the returned To object is equal to the corresponding bit in the object representation of from. The values of padding bits in the returned To object are unspecified.

If there is no value of type To corresponding to the value representation produced, the behavior is undefined. If there are multiple such values, which value is produced is unspecified.

This overload only participates in overload resolution if sizeof(To) == sizeof(From) and both To and From are TriviallyCopyable types.

This function template is constexpr if and only if each of To, From and the types of all subobjects of To and From:

  • is not a union type;
  • is not a pointer type;
  • is not a pointer to member type;
  • is not a volatile-qualified type; and
  • has no non-static data member of reference type.

[edit] Return value

An object of type To whose value representation is as described above.

[edit] Example