Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
roro47 committed Jun 27, 2024
1 parent 1790677 commit 64c16de
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions libredex/StlUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <algorithm>
#include <cstring>
#include <deque>
#include <vector>

Expand Down Expand Up @@ -45,9 +46,22 @@ size_t erase_if(Container& c, const Pred& pred) {
return removed;
}

template <typename To, typename From>
constexpr To bit_cast(const From& from) noexcept {
return __builtin_bit_cast(To, from);
template<class To, class From>
std::enable_if_t<
sizeof(To) == sizeof(From) &&
std::is_trivially_copyable_v<From> &&
std::is_trivially_copyable_v<To>,
To>
// constexpr support needs compiler magic
bit_cast(const From& src) noexcept
{
static_assert(std::is_trivially_constructible_v<To>,
"This implementation additionally requires "
"destination type to be trivially constructible");

To dst;
std::memcpy(&dst, &src, sizeof(To));
return dst;
}

} // namespace std20

0 comments on commit 64c16de

Please sign in to comment.