GCC build fix

This commit is contained in:
Shauren
2023-07-17 20:32:07 +02:00
parent 361fe56bc8
commit dfbf09f4b9
2 changed files with 27 additions and 2 deletions

View File

@@ -18,6 +18,13 @@
#ifndef TRINITY_ADVSTD_H
#define TRINITY_ADVSTD_H
#include <version>
#ifdef __cpp_lib_bit_cast
#include <bit>
#else
#include <cstring> // for memcpy
#endif
#include <compare>
// this namespace holds implementations of upcoming stdlib features that our c++ version doesn't have yet
@@ -26,6 +33,23 @@ namespace advstd
// libc++ is missing these two
[[nodiscard]] constexpr bool is_eq(std::partial_ordering cmp) noexcept { return cmp == 0; }
[[nodiscard]] constexpr bool is_neq(std::partial_ordering cmp) noexcept { return cmp != 0; }
#ifdef __cpp_lib_bit_cast
using std::bit_cast;
#else
// libstdc++ v10 is missing this
template <typename To, typename From,
std::enable_if_t<std::conjunction_v<
std::bool_constant<sizeof(To) == sizeof(From)>,
std::is_trivially_copyable<To>,
std::is_trivially_copyable<From>>, int> = 0>
[[nodiscard]] constexpr To bit_cast(From const& from) noexcept
{
To to;
std::memcpy(&to, &from, sizeof(To));
return to;
}
#endif
}
#endif

View File

@@ -39,6 +39,7 @@
#include "Transport.h"
#include "Unit.h"
#include "UpdateData.h"
#include "advstd.h"
#include <bit>
AreaTrigger::AreaTrigger() : WorldObject(false), MapObject(), _spawnId(0), _aurEff(nullptr), _maxSearchRadius(0.0f),
@@ -364,7 +365,7 @@ float AreaTrigger::GetScaleCurveValue(UF::ScaleCurve const& scaleCurve, float x)
// unpack ParameterCurve
if (*scaleCurve.ParameterCurve & 1)
return std::bit_cast<float>(*scaleCurve.ParameterCurve & ~1);
return advstd::bit_cast<float>(*scaleCurve.ParameterCurve & ~1);
std::array<DBCPosition2D, 2> points;
for (std::size_t i = 0; i < scaleCurve.Points.size(); ++i)
@@ -394,7 +395,7 @@ void AreaTrigger::SetScaleCurve(UF::MutableFieldReference<UF::ScaleCurve, false>
if (float const* simpleFloat = std::get_if<float>(&curve->Curve))
{
uint32 packedCurve = std::bit_cast<uint32>(*simpleFloat);
uint32 packedCurve = advstd::bit_cast<uint32>(*simpleFloat);
packedCurve |= 1;
SetUpdateFieldValue(scaleCurveMutator.ModifyValue(&UF::ScaleCurve::ParameterCurve), packedCurve);