diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Utilities/advstd.h | 24 | ||||
-rw-r--r-- | src/server/game/Entities/AreaTrigger/AreaTrigger.cpp | 5 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/common/Utilities/advstd.h b/src/common/Utilities/advstd.h index 5b9991854bf..5bdfb52b533 100644 --- a/src/common/Utilities/advstd.h +++ b/src/common/Utilities/advstd.h @@ -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 diff --git a/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp b/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp index 80a31903120..8bf33886a55 100644 --- a/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp +++ b/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp @@ -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); |