24 Numerics library [numerics]

24.6 Bit manipulation [bit]

24.6.3 Function template bit_­cast [bit.cast]

template<typename To, typename From> constexpr To bit_cast(const From& from) noexcept;
Returns: An object of type To.
Each bit of the value representation of the result is equal to the corresponding bit in the object representation of from.
Padding bits of the 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.
Remarks: This function shall not participate in overload resolution unless:
  • sizeof(To) == sizeof(From) is true;
  • is_­trivially_­copyable_­v<To> is true; and
  • is_­trivially_­copyable_­v<From> is true.
This function shall be constexpr if and only if To, From, and the types of all subobjects of To and From are types T such that:
  • is_­union_­v<T> is false;
  • is_­pointer_­v<T> is false;
  • is_­member_­pointer_­v<T> is false;
  • is_­volatile_­v<T> is false; and
  • T has no non-static data members of reference type.