From a43754266a7e8d9e867edd10050f86246da22069 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 12 Dec 2023 08:52:11 -0800 Subject: [PATCH] and (#1497) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1497 The lowest common denominator we have had for Yoga has been Clang 12 + MSVC 2017 stdlib. This has allowed Yoga to use C++ 20 language features, but not library features. React Native for mobile has not been bound to this restriction. Builds using that toolchain are being updated to latest MSVC 2019 stdlib (which has good C++ 20 library support), along with Clang 17 (or maybe a stop at 15) pending projects using `-fcoroutines-ts` being migrated to C++ 20. This tests out some C++ 20 standard library usages against the current Clang 12 + MSVC 2019 stdlib toolchain that didn't work before, and adds a couple concepts for better constraints/compiler error messages if misused. This bumps min-tested XCode (and minimum required) version to 14.3, matching a similar change for React Native. This should probably be bumped to 15 sometime before Apple starts requiring 15+ to go out to the iOS app store. We are approaching a practical support range of: 1. XCode >= 14.3 2. NDK >= 26 3. Clang/libc++ >= 14 4. GCC/libstdc++ >= 11 5. MSVC >= 16.11 (VS 2019) Changelog: [Internal] Reviewed By: cortinico Differential Revision: D51604487 fbshipit-source-id: d394d0d86672b69781b8ae071d87adcf944ddc72 --- .github/actions/setup-apple/action.yml | 4 ++++ .github/workflows/validate-apple.yml | 7 ++++-- enums.py | 13 ++++------- yoga/YGMacros.h | 8 +++---- yoga/bits/BitCast.h | 30 -------------------------- yoga/enums/Align.h | 13 ++++------- yoga/enums/Dimension.h | 13 ++++------- yoga/enums/Direction.h | 13 ++++------- yoga/enums/Display.h | 13 ++++------- yoga/enums/Edge.h | 13 ++++------- yoga/enums/Errata.h | 4 ++-- yoga/enums/ExperimentalFeature.h | 13 ++++------- yoga/enums/FlexDirection.h | 13 ++++------- yoga/enums/Gutter.h | 13 ++++------- yoga/enums/Justify.h | 13 ++++------- yoga/enums/LogLevel.h | 13 ++++------- yoga/enums/MeasureMode.h | 13 ++++------- yoga/enums/NodeType.h | 13 ++++------- yoga/enums/Overflow.h | 13 ++++------- yoga/enums/PositionType.h | 13 ++++------- yoga/enums/PrintOptions.h | 4 ++-- yoga/enums/Unit.h | 13 ++++------- yoga/enums/Wrap.h | 13 ++++------- yoga/enums/YogaEnums.h | 29 ++++++++++++++++++++----- yoga/numeric/Comparison.h | 13 +++++++---- yoga/style/CompactValue.h | 10 ++++----- 26 files changed, 123 insertions(+), 207 deletions(-) delete mode 100644 yoga/bits/BitCast.h diff --git a/.github/actions/setup-apple/action.yml b/.github/actions/setup-apple/action.yml index 6ef41f5806..4087ecbb74 100644 --- a/.github/actions/setup-apple/action.yml +++ b/.github/actions/setup-apple/action.yml @@ -7,3 +7,7 @@ runs: - name: Install Cocoapods shell: bash run: sudo gem install cocoapods + + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: 14.3.1 diff --git a/.github/workflows/validate-apple.yml b/.github/workflows/validate-apple.yml index 598ca2e830..3097cfe23d 100644 --- a/.github/workflows/validate-apple.yml +++ b/.github/workflows/validate-apple.yml @@ -11,7 +11,7 @@ on: jobs: lint-pods: name: Build [CocoaPods] - runs-on: macos-latest + runs-on: macos-13 steps: - uses: actions/checkout@v3 @@ -24,11 +24,14 @@ jobs: test: name: Build [SwiftPM] - runs-on: macos-latest + runs-on: macos-13 steps: - uses: actions/checkout@v3 + - name: Setup + uses: ./.github/actions/setup-apple + - name: Build Debug run: swift build -c debug diff --git a/enums.py b/enums.py index 7e2a918edc..7fe3732b49 100755 --- a/enums.py +++ b/enums.py @@ -174,20 +174,15 @@ def to_hyphenated_lower(symbol): f.write(f"YG_DEFINE_ENUM_FLAG_OPERATORS({name})\n\n") else: f.write("template <>\n") - f.write(f"constexpr inline int32_t ordinalCount<{name}>() {{\n") + f.write(f"constexpr int32_t ordinalCount<{name}>() {{\n") f.write(f" return {len(values)};\n") - f.write("} \n\n") + f.write("}\n\n") - f.write("template <>\n") - f.write(f"constexpr inline int32_t bitCount<{name}>() {{\n") - f.write(f" return {math.ceil(math.log(len(values), 2))};\n") - f.write("} \n\n") - - f.write(f"constexpr inline {name} scopedEnum(YG{name} unscoped) {{\n") + f.write(f"constexpr {name} scopedEnum(YG{name} unscoped) {{\n") f.write(f" return static_cast<{name}>(unscoped);\n") f.write("}\n\n") - f.write(f"constexpr inline YG{name} unscopedEnum({name} scoped) {{\n") + f.write(f"constexpr YG{name} unscopedEnum({name} scoped) {{\n") f.write(f" return static_cast(scoped);\n") f.write("}\n\n") diff --git a/yoga/YGMacros.h b/yoga/YGMacros.h index 6460297a3d..6d1becce77 100644 --- a/yoga/YGMacros.h +++ b/yoga/YGMacros.h @@ -49,21 +49,21 @@ #ifdef __cplusplus #define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \ extern "C++" { \ - constexpr inline name operator~(name a) { \ + constexpr name operator~(name a) { \ return static_cast( \ ~static_cast::type>(a)); \ } \ - constexpr inline name operator|(name a, name b) { \ + constexpr name operator|(name a, name b) { \ return static_cast( \ static_cast::type>(a) | \ static_cast::type>(b)); \ } \ - constexpr inline name operator&(name a, name b) { \ + constexpr name operator&(name a, name b) { \ return static_cast( \ static_cast::type>(a) & \ static_cast::type>(b)); \ } \ - constexpr inline name operator^(name a, name b) { \ + constexpr name operator^(name a, name b) { \ return static_cast( \ static_cast::type>(a) ^ \ static_cast::type>(b)); \ diff --git a/yoga/bits/BitCast.h b/yoga/bits/BitCast.h deleted file mode 100644 index 13fb0e41f2..0000000000 --- a/yoga/bits/BitCast.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -namespace facebook::yoga { - -// Polyfill for std::bit_cast() from C++20, to allow safe type punning -// https://en.cppreference.com/w/cpp/numeric/bit_cast -// TODO: Remove when we upgrade to NDK 26+ -template -std::enable_if_t< - sizeof(To) == sizeof(From) && std::is_trivially_copyable_v && - std::is_trivially_copyable_v && - std::is_trivially_constructible_v, - To> -bit_cast(const From& src) noexcept { - To dst; - std::memcpy(&dst, &src, sizeof(To)); - return dst; -} - -} // namespace facebook::yoga diff --git a/yoga/enums/Align.h b/yoga/enums/Align.h index 67777fc31b..3896fe2b8b 100644 --- a/yoga/enums/Align.h +++ b/yoga/enums/Align.h @@ -28,20 +28,15 @@ enum class Align : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 9; -} - -template <> -constexpr inline int32_t bitCount() { - return 4; -} +} -constexpr inline Align scopedEnum(YGAlign unscoped) { +constexpr Align scopedEnum(YGAlign unscoped) { return static_cast(unscoped); } -constexpr inline YGAlign unscopedEnum(Align scoped) { +constexpr YGAlign unscopedEnum(Align scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Dimension.h b/yoga/enums/Dimension.h index 2274a980a5..965901525b 100644 --- a/yoga/enums/Dimension.h +++ b/yoga/enums/Dimension.h @@ -21,20 +21,15 @@ enum class Dimension : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 2; -} - -template <> -constexpr inline int32_t bitCount() { - return 1; -} +} -constexpr inline Dimension scopedEnum(YGDimension unscoped) { +constexpr Dimension scopedEnum(YGDimension unscoped) { return static_cast(unscoped); } -constexpr inline YGDimension unscopedEnum(Dimension scoped) { +constexpr YGDimension unscopedEnum(Dimension scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Direction.h b/yoga/enums/Direction.h index 1b5e19c93c..5bbabaecde 100644 --- a/yoga/enums/Direction.h +++ b/yoga/enums/Direction.h @@ -22,20 +22,15 @@ enum class Direction : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 3; -} - -template <> -constexpr inline int32_t bitCount() { - return 2; -} +} -constexpr inline Direction scopedEnum(YGDirection unscoped) { +constexpr Direction scopedEnum(YGDirection unscoped) { return static_cast(unscoped); } -constexpr inline YGDirection unscopedEnum(Direction scoped) { +constexpr YGDirection unscopedEnum(Direction scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Display.h b/yoga/enums/Display.h index c1d8c7a82e..418ebc1dcd 100644 --- a/yoga/enums/Display.h +++ b/yoga/enums/Display.h @@ -21,20 +21,15 @@ enum class Display : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 2; -} - -template <> -constexpr inline int32_t bitCount() { - return 1; -} +} -constexpr inline Display scopedEnum(YGDisplay unscoped) { +constexpr Display scopedEnum(YGDisplay unscoped) { return static_cast(unscoped); } -constexpr inline YGDisplay unscopedEnum(Display scoped) { +constexpr YGDisplay unscopedEnum(Display scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Edge.h b/yoga/enums/Edge.h index d6d2b0ee66..3ab6a33faf 100644 --- a/yoga/enums/Edge.h +++ b/yoga/enums/Edge.h @@ -28,20 +28,15 @@ enum class Edge : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 9; -} - -template <> -constexpr inline int32_t bitCount() { - return 4; -} +} -constexpr inline Edge scopedEnum(YGEdge unscoped) { +constexpr Edge scopedEnum(YGEdge unscoped) { return static_cast(unscoped); } -constexpr inline YGEdge unscopedEnum(Edge scoped) { +constexpr YGEdge unscopedEnum(Edge scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Errata.h b/yoga/enums/Errata.h index 5bda0c0b9c..e97b66c3e7 100644 --- a/yoga/enums/Errata.h +++ b/yoga/enums/Errata.h @@ -27,11 +27,11 @@ enum class Errata : uint32_t { YG_DEFINE_ENUM_FLAG_OPERATORS(Errata) -constexpr inline Errata scopedEnum(YGErrata unscoped) { +constexpr Errata scopedEnum(YGErrata unscoped) { return static_cast(unscoped); } -constexpr inline YGErrata unscopedEnum(Errata scoped) { +constexpr YGErrata unscopedEnum(Errata scoped) { return static_cast(scoped); } diff --git a/yoga/enums/ExperimentalFeature.h b/yoga/enums/ExperimentalFeature.h index 6ed358155b..4c366fb43e 100644 --- a/yoga/enums/ExperimentalFeature.h +++ b/yoga/enums/ExperimentalFeature.h @@ -21,20 +21,15 @@ enum class ExperimentalFeature : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 2; -} - -template <> -constexpr inline int32_t bitCount() { - return 1; -} +} -constexpr inline ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) { +constexpr ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) { return static_cast(unscoped); } -constexpr inline YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) { +constexpr YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) { return static_cast(scoped); } diff --git a/yoga/enums/FlexDirection.h b/yoga/enums/FlexDirection.h index 45f6497ca4..d2d3f6105d 100644 --- a/yoga/enums/FlexDirection.h +++ b/yoga/enums/FlexDirection.h @@ -23,20 +23,15 @@ enum class FlexDirection : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 4; -} - -template <> -constexpr inline int32_t bitCount() { - return 2; -} +} -constexpr inline FlexDirection scopedEnum(YGFlexDirection unscoped) { +constexpr FlexDirection scopedEnum(YGFlexDirection unscoped) { return static_cast(unscoped); } -constexpr inline YGFlexDirection unscopedEnum(FlexDirection scoped) { +constexpr YGFlexDirection unscopedEnum(FlexDirection scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Gutter.h b/yoga/enums/Gutter.h index 5c0f4a254e..f16bbbcdf4 100644 --- a/yoga/enums/Gutter.h +++ b/yoga/enums/Gutter.h @@ -22,20 +22,15 @@ enum class Gutter : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 3; -} - -template <> -constexpr inline int32_t bitCount() { - return 2; -} +} -constexpr inline Gutter scopedEnum(YGGutter unscoped) { +constexpr Gutter scopedEnum(YGGutter unscoped) { return static_cast(unscoped); } -constexpr inline YGGutter unscopedEnum(Gutter scoped) { +constexpr YGGutter unscopedEnum(Gutter scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Justify.h b/yoga/enums/Justify.h index 870a3cb2a7..255baa6e27 100644 --- a/yoga/enums/Justify.h +++ b/yoga/enums/Justify.h @@ -25,20 +25,15 @@ enum class Justify : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 6; -} - -template <> -constexpr inline int32_t bitCount() { - return 3; -} +} -constexpr inline Justify scopedEnum(YGJustify unscoped) { +constexpr Justify scopedEnum(YGJustify unscoped) { return static_cast(unscoped); } -constexpr inline YGJustify unscopedEnum(Justify scoped) { +constexpr YGJustify unscopedEnum(Justify scoped) { return static_cast(scoped); } diff --git a/yoga/enums/LogLevel.h b/yoga/enums/LogLevel.h index 45cac9fe39..d4b2c36019 100644 --- a/yoga/enums/LogLevel.h +++ b/yoga/enums/LogLevel.h @@ -25,20 +25,15 @@ enum class LogLevel : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 6; -} - -template <> -constexpr inline int32_t bitCount() { - return 3; -} +} -constexpr inline LogLevel scopedEnum(YGLogLevel unscoped) { +constexpr LogLevel scopedEnum(YGLogLevel unscoped) { return static_cast(unscoped); } -constexpr inline YGLogLevel unscopedEnum(LogLevel scoped) { +constexpr YGLogLevel unscopedEnum(LogLevel scoped) { return static_cast(scoped); } diff --git a/yoga/enums/MeasureMode.h b/yoga/enums/MeasureMode.h index 80fbcc599f..39e2102fff 100644 --- a/yoga/enums/MeasureMode.h +++ b/yoga/enums/MeasureMode.h @@ -22,20 +22,15 @@ enum class MeasureMode : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 3; -} - -template <> -constexpr inline int32_t bitCount() { - return 2; -} +} -constexpr inline MeasureMode scopedEnum(YGMeasureMode unscoped) { +constexpr MeasureMode scopedEnum(YGMeasureMode unscoped) { return static_cast(unscoped); } -constexpr inline YGMeasureMode unscopedEnum(MeasureMode scoped) { +constexpr YGMeasureMode unscopedEnum(MeasureMode scoped) { return static_cast(scoped); } diff --git a/yoga/enums/NodeType.h b/yoga/enums/NodeType.h index 782b163c2e..dc881be831 100644 --- a/yoga/enums/NodeType.h +++ b/yoga/enums/NodeType.h @@ -21,20 +21,15 @@ enum class NodeType : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 2; -} - -template <> -constexpr inline int32_t bitCount() { - return 1; -} +} -constexpr inline NodeType scopedEnum(YGNodeType unscoped) { +constexpr NodeType scopedEnum(YGNodeType unscoped) { return static_cast(unscoped); } -constexpr inline YGNodeType unscopedEnum(NodeType scoped) { +constexpr YGNodeType unscopedEnum(NodeType scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Overflow.h b/yoga/enums/Overflow.h index 1d29103e62..20901b02c0 100644 --- a/yoga/enums/Overflow.h +++ b/yoga/enums/Overflow.h @@ -22,20 +22,15 @@ enum class Overflow : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 3; -} - -template <> -constexpr inline int32_t bitCount() { - return 2; -} +} -constexpr inline Overflow scopedEnum(YGOverflow unscoped) { +constexpr Overflow scopedEnum(YGOverflow unscoped) { return static_cast(unscoped); } -constexpr inline YGOverflow unscopedEnum(Overflow scoped) { +constexpr YGOverflow unscopedEnum(Overflow scoped) { return static_cast(scoped); } diff --git a/yoga/enums/PositionType.h b/yoga/enums/PositionType.h index bde2b1896f..8a552aacba 100644 --- a/yoga/enums/PositionType.h +++ b/yoga/enums/PositionType.h @@ -22,20 +22,15 @@ enum class PositionType : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 3; -} - -template <> -constexpr inline int32_t bitCount() { - return 2; -} +} -constexpr inline PositionType scopedEnum(YGPositionType unscoped) { +constexpr PositionType scopedEnum(YGPositionType unscoped) { return static_cast(unscoped); } -constexpr inline YGPositionType unscopedEnum(PositionType scoped) { +constexpr YGPositionType unscopedEnum(PositionType scoped) { return static_cast(scoped); } diff --git a/yoga/enums/PrintOptions.h b/yoga/enums/PrintOptions.h index 90d0043c74..5970bafb47 100644 --- a/yoga/enums/PrintOptions.h +++ b/yoga/enums/PrintOptions.h @@ -23,11 +23,11 @@ enum class PrintOptions : uint32_t { YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions) -constexpr inline PrintOptions scopedEnum(YGPrintOptions unscoped) { +constexpr PrintOptions scopedEnum(YGPrintOptions unscoped) { return static_cast(unscoped); } -constexpr inline YGPrintOptions unscopedEnum(PrintOptions scoped) { +constexpr YGPrintOptions unscopedEnum(PrintOptions scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Unit.h b/yoga/enums/Unit.h index 36efe95aaf..57bd196970 100644 --- a/yoga/enums/Unit.h +++ b/yoga/enums/Unit.h @@ -23,20 +23,15 @@ enum class Unit : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 4; -} - -template <> -constexpr inline int32_t bitCount() { - return 2; -} +} -constexpr inline Unit scopedEnum(YGUnit unscoped) { +constexpr Unit scopedEnum(YGUnit unscoped) { return static_cast(unscoped); } -constexpr inline YGUnit unscopedEnum(Unit scoped) { +constexpr YGUnit unscopedEnum(Unit scoped) { return static_cast(scoped); } diff --git a/yoga/enums/Wrap.h b/yoga/enums/Wrap.h index ae380a4448..96552b7b2a 100644 --- a/yoga/enums/Wrap.h +++ b/yoga/enums/Wrap.h @@ -22,20 +22,15 @@ enum class Wrap : uint8_t { }; template <> -constexpr inline int32_t ordinalCount() { +constexpr int32_t ordinalCount() { return 3; -} - -template <> -constexpr inline int32_t bitCount() { - return 2; -} +} -constexpr inline Wrap scopedEnum(YGWrap unscoped) { +constexpr Wrap scopedEnum(YGWrap unscoped) { return static_cast(unscoped); } -constexpr inline YGWrap unscopedEnum(Wrap scoped) { +constexpr YGWrap unscopedEnum(Wrap scoped) { return static_cast(scoped); } diff --git a/yoga/enums/YogaEnums.h b/yoga/enums/YogaEnums.h index a3e1191de1..de446621d5 100644 --- a/yoga/enums/YogaEnums.h +++ b/yoga/enums/YogaEnums.h @@ -7,25 +7,44 @@ #pragma once +#include #include #include namespace facebook::yoga { +/** + * Concept for any enum/enum class + */ template -constexpr inline int32_t ordinalCount(); +concept Enumeration = std::is_enum_v; /** - * Count of bits needed to represent every ordinal + * Count of ordinals in a Yoga enum which is sequential + */ +template +constexpr int32_t ordinalCount(); + +/** + * Concept for a yoga enum which is sequential */ template -constexpr inline int32_t bitCount(); +concept HasOrdinality = (ordinalCount() > 0); + +/** + * Count of bits needed to represent every ordinal + */ +template +constexpr int32_t bitCount() { + return std::bit_width( + static_cast>(ordinalCount() - 1)); +} /** * Polyfill of C++ 23 to_underlying() * https://en.cppreference.com/w/cpp/utility/to_underlying */ -constexpr auto to_underlying(auto e) noexcept { +constexpr auto to_underlying(Enumeration auto e) noexcept { return static_cast>(e); } @@ -33,7 +52,7 @@ constexpr auto to_underlying(auto e) noexcept { * Convenience function to iterate through every value in a Yoga enum as part of * a range-based for loop. */ -template +template auto ordinals() { struct Iterator { EnumT e{}; diff --git a/yoga/numeric/Comparison.h b/yoga/numeric/Comparison.h index 3bf1037b9c..729589b934 100644 --- a/yoga/numeric/Comparison.h +++ b/yoga/numeric/Comparison.h @@ -10,27 +10,32 @@ #include #include #include +#include #include namespace facebook::yoga { -constexpr bool isUndefined(auto value) { +constexpr bool isUndefined(std::floating_point auto value) { return value != value; } -constexpr bool isDefined(auto value) { +constexpr bool isDefined(std::floating_point auto value) { return !isUndefined(value); } -constexpr auto maxOrDefined(auto a, auto b) { +constexpr auto maxOrDefined( + std::floating_point auto a, + std::floating_point auto b) { if (yoga::isDefined(a) && yoga::isDefined(b)) { return std::max(a, b); } return yoga::isUndefined(a) ? b : a; } -constexpr auto minOrDefined(auto a, auto b) { +constexpr auto minOrDefined( + std::floating_point auto a, + std::floating_point auto b) { if (yoga::isDefined(a) && yoga::isDefined(b)) { return std::min(a, b); } diff --git a/yoga/style/CompactValue.h b/yoga/style/CompactValue.h index c32dd9276f..d7884e1d6f 100644 --- a/yoga/style/CompactValue.h +++ b/yoga/style/CompactValue.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -14,7 +15,6 @@ #include #include -#include #include static_assert( @@ -69,7 +69,7 @@ class YG_EXPORT CompactValue { } uint32_t unitBit = Unit == YGUnitPercent ? PERCENT_BIT : 0; - auto data = yoga::bit_cast(value); + auto data = std::bit_cast(value); data -= BIAS; data |= unitBit; return {data}; @@ -112,7 +112,7 @@ class YG_EXPORT CompactValue { return YGValue{0.0f, YGUnitPercent}; } - if (std::isnan(yoga::bit_cast(repr_))) { + if (std::isnan(std::bit_cast(repr_))) { return YGValueUndefined; } @@ -121,14 +121,14 @@ class YG_EXPORT CompactValue { data += BIAS; return YGValue{ - yoga::bit_cast(data), + std::bit_cast(data), repr_ & 0x40000000 ? YGUnitPercent : YGUnitPoint}; } bool isUndefined() const noexcept { return ( repr_ != AUTO_BITS && repr_ != ZERO_BITS_POINT && - repr_ != ZERO_BITS_PERCENT && std::isnan(yoga::bit_cast(repr_))); + repr_ != ZERO_BITS_PERCENT && std::isnan(std::bit_cast(repr_))); } bool isDefined() const noexcept {