Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency to bit_cast in tests #1255

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions test/tts/tts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,24 @@ ::tts::logger{}.check
#include <cstdint>
#include <type_traits>
#include <utility>
#if !defined(__cpp_lib_bit_cast)
# include <cstring>
#endif
namespace tts::detail
{
inline auto as_int(float a) noexcept { return std::bit_cast<std::int32_t>(a); }
inline auto as_int(double a) noexcept { return std::bit_cast<std::int64_t>(a); }
#if !defined(__cpp_lib_bit_cast)
template <class To, class From>
To bit_cast(const From& src) noexcept requires(sizeof(To) == sizeof(From))
{
To dst;
std::memcpy(&dst, &src, sizeof(To));
return dst;
}
#else
using std::bit_cast;
#endif
inline auto as_int(float a) noexcept { return bit_cast<std::int32_t>(a); }
inline auto as_int(double a) noexcept { return bit_cast<std::int64_t>(a); }
template<typename T> inline auto bitinteger(T a) noexcept
{
auto ia = as_int(a);
Expand Down