Function bit_cast
Synopsis
#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()))
Description
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 aconstexpr
context would require compiler magic) - requires that
To
beDefaultConstructible
- it is
noexcept( noexcept( To() ) )
(the standard version is unconditionallynoexcept
)
Source
Line 50 in breeze/conversion/bit_cast.hpp.