Function bit_cast


#include "breeze/conversion/bit_cast.hpp"

template <typename To, typename From>
std::enable_if_t< sizeof(To)==sizeof(From) &&std::is_trivially_copyable< To >::value &&std::is_trivially_copyable< From >::value, To > bit_cast(From const &from) noexcept(noexcept(To()))


Copies the object representation of the object referred to by from into an object t of type std::remove_const_t< To > and returns t.

This template participates in overload resolution only if To and From have the same size and are both TriviallyCopyable.

It is is an approximation of C++20's std::bit_cast(), for usage with C++14 and C++17.

The differences from the standard version are:

  • it is not constexpr (allowing usage in a constexpr context would require compiler magic)
  • requires that To be DefaultConstructible
  • it is noexcept( noexcept( To() ) ) (the standard version is unconditionally noexcept)


Line 50 in breeze/conversion/bit_cast.hpp.