<bit> and <concepts> (#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
This commit is contained in:
Nick Gerleman
2023-12-12 08:52:11 -08:00
committed by Facebook GitHub Bot
parent ab37ed70ae
commit a43754266a
26 changed files with 123 additions and 207 deletions

View File

@@ -7,3 +7,7 @@ runs:
- name: Install Cocoapods - name: Install Cocoapods
shell: bash shell: bash
run: sudo gem install cocoapods run: sudo gem install cocoapods
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 14.3.1

View File

@@ -11,7 +11,7 @@ on:
jobs: jobs:
lint-pods: lint-pods:
name: Build [CocoaPods] name: Build [CocoaPods]
runs-on: macos-latest runs-on: macos-13
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -24,11 +24,14 @@ jobs:
test: test:
name: Build [SwiftPM] name: Build [SwiftPM]
runs-on: macos-latest runs-on: macos-13
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/setup-apple
- name: Build Debug - name: Build Debug
run: swift build -c debug run: swift build -c debug

View File

@@ -174,20 +174,15 @@ for name, values in sorted(ENUMS.items()):
f.write(f"YG_DEFINE_ENUM_FLAG_OPERATORS({name})\n\n") f.write(f"YG_DEFINE_ENUM_FLAG_OPERATORS({name})\n\n")
else: else:
f.write("template <>\n") 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(f" return {len(values)};\n")
f.write("} \n\n") f.write("}\n\n")
f.write("template <>\n") f.write(f"constexpr {name} scopedEnum(YG{name} unscoped) {{\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" return static_cast<{name}>(unscoped);\n") f.write(f" return static_cast<{name}>(unscoped);\n")
f.write("}\n\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<YG{name}>(scoped);\n") f.write(f" return static_cast<YG{name}>(scoped);\n")
f.write("}\n\n") f.write("}\n\n")

View File

@@ -49,21 +49,21 @@
#ifdef __cplusplus #ifdef __cplusplus
#define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \ #define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \
extern "C++" { \ extern "C++" { \
constexpr inline name operator~(name a) { \ constexpr name operator~(name a) { \
return static_cast<name>( \ return static_cast<name>( \
~static_cast<std::underlying_type<name>::type>(a)); \ ~static_cast<std::underlying_type<name>::type>(a)); \
} \ } \
constexpr inline name operator|(name a, name b) { \ constexpr name operator|(name a, name b) { \
return static_cast<name>( \ return static_cast<name>( \
static_cast<std::underlying_type<name>::type>(a) | \ static_cast<std::underlying_type<name>::type>(a) | \
static_cast<std::underlying_type<name>::type>(b)); \ static_cast<std::underlying_type<name>::type>(b)); \
} \ } \
constexpr inline name operator&(name a, name b) { \ constexpr name operator&(name a, name b) { \
return static_cast<name>( \ return static_cast<name>( \
static_cast<std::underlying_type<name>::type>(a) & \ static_cast<std::underlying_type<name>::type>(a) & \
static_cast<std::underlying_type<name>::type>(b)); \ static_cast<std::underlying_type<name>::type>(b)); \
} \ } \
constexpr inline name operator^(name a, name b) { \ constexpr name operator^(name a, name b) { \
return static_cast<name>( \ return static_cast<name>( \
static_cast<std::underlying_type<name>::type>(a) ^ \ static_cast<std::underlying_type<name>::type>(a) ^ \
static_cast<std::underlying_type<name>::type>(b)); \ static_cast<std::underlying_type<name>::type>(b)); \

View File

@@ -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 <cstring>
#include <type_traits>
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 <class To, class From>
std::enable_if_t<
sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> &&
std::is_trivially_copyable_v<To> &&
std::is_trivially_constructible_v<To>,
To>
bit_cast(const From& src) noexcept {
To dst;
std::memcpy(&dst, &src, sizeof(To));
return dst;
}
} // namespace facebook::yoga

View File

@@ -28,20 +28,15 @@ enum class Align : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Align>() { constexpr int32_t ordinalCount<Align>() {
return 9; return 9;
} }
template <> constexpr Align scopedEnum(YGAlign unscoped) {
constexpr inline int32_t bitCount<Align>() {
return 4;
}
constexpr inline Align scopedEnum(YGAlign unscoped) {
return static_cast<Align>(unscoped); return static_cast<Align>(unscoped);
} }
constexpr inline YGAlign unscopedEnum(Align scoped) { constexpr YGAlign unscopedEnum(Align scoped) {
return static_cast<YGAlign>(scoped); return static_cast<YGAlign>(scoped);
} }

View File

@@ -21,20 +21,15 @@ enum class Dimension : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Dimension>() { constexpr int32_t ordinalCount<Dimension>() {
return 2; return 2;
} }
template <> constexpr Dimension scopedEnum(YGDimension unscoped) {
constexpr inline int32_t bitCount<Dimension>() {
return 1;
}
constexpr inline Dimension scopedEnum(YGDimension unscoped) {
return static_cast<Dimension>(unscoped); return static_cast<Dimension>(unscoped);
} }
constexpr inline YGDimension unscopedEnum(Dimension scoped) { constexpr YGDimension unscopedEnum(Dimension scoped) {
return static_cast<YGDimension>(scoped); return static_cast<YGDimension>(scoped);
} }

View File

@@ -22,20 +22,15 @@ enum class Direction : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Direction>() { constexpr int32_t ordinalCount<Direction>() {
return 3; return 3;
} }
template <> constexpr Direction scopedEnum(YGDirection unscoped) {
constexpr inline int32_t bitCount<Direction>() {
return 2;
}
constexpr inline Direction scopedEnum(YGDirection unscoped) {
return static_cast<Direction>(unscoped); return static_cast<Direction>(unscoped);
} }
constexpr inline YGDirection unscopedEnum(Direction scoped) { constexpr YGDirection unscopedEnum(Direction scoped) {
return static_cast<YGDirection>(scoped); return static_cast<YGDirection>(scoped);
} }

View File

@@ -21,20 +21,15 @@ enum class Display : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Display>() { constexpr int32_t ordinalCount<Display>() {
return 2; return 2;
} }
template <> constexpr Display scopedEnum(YGDisplay unscoped) {
constexpr inline int32_t bitCount<Display>() {
return 1;
}
constexpr inline Display scopedEnum(YGDisplay unscoped) {
return static_cast<Display>(unscoped); return static_cast<Display>(unscoped);
} }
constexpr inline YGDisplay unscopedEnum(Display scoped) { constexpr YGDisplay unscopedEnum(Display scoped) {
return static_cast<YGDisplay>(scoped); return static_cast<YGDisplay>(scoped);
} }

View File

@@ -28,20 +28,15 @@ enum class Edge : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Edge>() { constexpr int32_t ordinalCount<Edge>() {
return 9; return 9;
} }
template <> constexpr Edge scopedEnum(YGEdge unscoped) {
constexpr inline int32_t bitCount<Edge>() {
return 4;
}
constexpr inline Edge scopedEnum(YGEdge unscoped) {
return static_cast<Edge>(unscoped); return static_cast<Edge>(unscoped);
} }
constexpr inline YGEdge unscopedEnum(Edge scoped) { constexpr YGEdge unscopedEnum(Edge scoped) {
return static_cast<YGEdge>(scoped); return static_cast<YGEdge>(scoped);
} }

View File

@@ -27,11 +27,11 @@ enum class Errata : uint32_t {
YG_DEFINE_ENUM_FLAG_OPERATORS(Errata) YG_DEFINE_ENUM_FLAG_OPERATORS(Errata)
constexpr inline Errata scopedEnum(YGErrata unscoped) { constexpr Errata scopedEnum(YGErrata unscoped) {
return static_cast<Errata>(unscoped); return static_cast<Errata>(unscoped);
} }
constexpr inline YGErrata unscopedEnum(Errata scoped) { constexpr YGErrata unscopedEnum(Errata scoped) {
return static_cast<YGErrata>(scoped); return static_cast<YGErrata>(scoped);
} }

View File

@@ -21,20 +21,15 @@ enum class ExperimentalFeature : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<ExperimentalFeature>() { constexpr int32_t ordinalCount<ExperimentalFeature>() {
return 2; return 2;
} }
template <> constexpr ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) {
constexpr inline int32_t bitCount<ExperimentalFeature>() {
return 1;
}
constexpr inline ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) {
return static_cast<ExperimentalFeature>(unscoped); return static_cast<ExperimentalFeature>(unscoped);
} }
constexpr inline YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) { constexpr YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) {
return static_cast<YGExperimentalFeature>(scoped); return static_cast<YGExperimentalFeature>(scoped);
} }

View File

@@ -23,20 +23,15 @@ enum class FlexDirection : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<FlexDirection>() { constexpr int32_t ordinalCount<FlexDirection>() {
return 4; return 4;
} }
template <> constexpr FlexDirection scopedEnum(YGFlexDirection unscoped) {
constexpr inline int32_t bitCount<FlexDirection>() {
return 2;
}
constexpr inline FlexDirection scopedEnum(YGFlexDirection unscoped) {
return static_cast<FlexDirection>(unscoped); return static_cast<FlexDirection>(unscoped);
} }
constexpr inline YGFlexDirection unscopedEnum(FlexDirection scoped) { constexpr YGFlexDirection unscopedEnum(FlexDirection scoped) {
return static_cast<YGFlexDirection>(scoped); return static_cast<YGFlexDirection>(scoped);
} }

View File

@@ -22,20 +22,15 @@ enum class Gutter : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Gutter>() { constexpr int32_t ordinalCount<Gutter>() {
return 3; return 3;
} }
template <> constexpr Gutter scopedEnum(YGGutter unscoped) {
constexpr inline int32_t bitCount<Gutter>() {
return 2;
}
constexpr inline Gutter scopedEnum(YGGutter unscoped) {
return static_cast<Gutter>(unscoped); return static_cast<Gutter>(unscoped);
} }
constexpr inline YGGutter unscopedEnum(Gutter scoped) { constexpr YGGutter unscopedEnum(Gutter scoped) {
return static_cast<YGGutter>(scoped); return static_cast<YGGutter>(scoped);
} }

View File

@@ -25,20 +25,15 @@ enum class Justify : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Justify>() { constexpr int32_t ordinalCount<Justify>() {
return 6; return 6;
} }
template <> constexpr Justify scopedEnum(YGJustify unscoped) {
constexpr inline int32_t bitCount<Justify>() {
return 3;
}
constexpr inline Justify scopedEnum(YGJustify unscoped) {
return static_cast<Justify>(unscoped); return static_cast<Justify>(unscoped);
} }
constexpr inline YGJustify unscopedEnum(Justify scoped) { constexpr YGJustify unscopedEnum(Justify scoped) {
return static_cast<YGJustify>(scoped); return static_cast<YGJustify>(scoped);
} }

View File

@@ -25,20 +25,15 @@ enum class LogLevel : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<LogLevel>() { constexpr int32_t ordinalCount<LogLevel>() {
return 6; return 6;
} }
template <> constexpr LogLevel scopedEnum(YGLogLevel unscoped) {
constexpr inline int32_t bitCount<LogLevel>() {
return 3;
}
constexpr inline LogLevel scopedEnum(YGLogLevel unscoped) {
return static_cast<LogLevel>(unscoped); return static_cast<LogLevel>(unscoped);
} }
constexpr inline YGLogLevel unscopedEnum(LogLevel scoped) { constexpr YGLogLevel unscopedEnum(LogLevel scoped) {
return static_cast<YGLogLevel>(scoped); return static_cast<YGLogLevel>(scoped);
} }

View File

@@ -22,20 +22,15 @@ enum class MeasureMode : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<MeasureMode>() { constexpr int32_t ordinalCount<MeasureMode>() {
return 3; return 3;
} }
template <> constexpr MeasureMode scopedEnum(YGMeasureMode unscoped) {
constexpr inline int32_t bitCount<MeasureMode>() {
return 2;
}
constexpr inline MeasureMode scopedEnum(YGMeasureMode unscoped) {
return static_cast<MeasureMode>(unscoped); return static_cast<MeasureMode>(unscoped);
} }
constexpr inline YGMeasureMode unscopedEnum(MeasureMode scoped) { constexpr YGMeasureMode unscopedEnum(MeasureMode scoped) {
return static_cast<YGMeasureMode>(scoped); return static_cast<YGMeasureMode>(scoped);
} }

View File

@@ -21,20 +21,15 @@ enum class NodeType : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<NodeType>() { constexpr int32_t ordinalCount<NodeType>() {
return 2; return 2;
} }
template <> constexpr NodeType scopedEnum(YGNodeType unscoped) {
constexpr inline int32_t bitCount<NodeType>() {
return 1;
}
constexpr inline NodeType scopedEnum(YGNodeType unscoped) {
return static_cast<NodeType>(unscoped); return static_cast<NodeType>(unscoped);
} }
constexpr inline YGNodeType unscopedEnum(NodeType scoped) { constexpr YGNodeType unscopedEnum(NodeType scoped) {
return static_cast<YGNodeType>(scoped); return static_cast<YGNodeType>(scoped);
} }

View File

@@ -22,20 +22,15 @@ enum class Overflow : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Overflow>() { constexpr int32_t ordinalCount<Overflow>() {
return 3; return 3;
} }
template <> constexpr Overflow scopedEnum(YGOverflow unscoped) {
constexpr inline int32_t bitCount<Overflow>() {
return 2;
}
constexpr inline Overflow scopedEnum(YGOverflow unscoped) {
return static_cast<Overflow>(unscoped); return static_cast<Overflow>(unscoped);
} }
constexpr inline YGOverflow unscopedEnum(Overflow scoped) { constexpr YGOverflow unscopedEnum(Overflow scoped) {
return static_cast<YGOverflow>(scoped); return static_cast<YGOverflow>(scoped);
} }

View File

@@ -22,20 +22,15 @@ enum class PositionType : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<PositionType>() { constexpr int32_t ordinalCount<PositionType>() {
return 3; return 3;
} }
template <> constexpr PositionType scopedEnum(YGPositionType unscoped) {
constexpr inline int32_t bitCount<PositionType>() {
return 2;
}
constexpr inline PositionType scopedEnum(YGPositionType unscoped) {
return static_cast<PositionType>(unscoped); return static_cast<PositionType>(unscoped);
} }
constexpr inline YGPositionType unscopedEnum(PositionType scoped) { constexpr YGPositionType unscopedEnum(PositionType scoped) {
return static_cast<YGPositionType>(scoped); return static_cast<YGPositionType>(scoped);
} }

View File

@@ -23,11 +23,11 @@ enum class PrintOptions : uint32_t {
YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions) YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions)
constexpr inline PrintOptions scopedEnum(YGPrintOptions unscoped) { constexpr PrintOptions scopedEnum(YGPrintOptions unscoped) {
return static_cast<PrintOptions>(unscoped); return static_cast<PrintOptions>(unscoped);
} }
constexpr inline YGPrintOptions unscopedEnum(PrintOptions scoped) { constexpr YGPrintOptions unscopedEnum(PrintOptions scoped) {
return static_cast<YGPrintOptions>(scoped); return static_cast<YGPrintOptions>(scoped);
} }

View File

@@ -23,20 +23,15 @@ enum class Unit : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Unit>() { constexpr int32_t ordinalCount<Unit>() {
return 4; return 4;
} }
template <> constexpr Unit scopedEnum(YGUnit unscoped) {
constexpr inline int32_t bitCount<Unit>() {
return 2;
}
constexpr inline Unit scopedEnum(YGUnit unscoped) {
return static_cast<Unit>(unscoped); return static_cast<Unit>(unscoped);
} }
constexpr inline YGUnit unscopedEnum(Unit scoped) { constexpr YGUnit unscopedEnum(Unit scoped) {
return static_cast<YGUnit>(scoped); return static_cast<YGUnit>(scoped);
} }

View File

@@ -22,20 +22,15 @@ enum class Wrap : uint8_t {
}; };
template <> template <>
constexpr inline int32_t ordinalCount<Wrap>() { constexpr int32_t ordinalCount<Wrap>() {
return 3; return 3;
} }
template <> constexpr Wrap scopedEnum(YGWrap unscoped) {
constexpr inline int32_t bitCount<Wrap>() {
return 2;
}
constexpr inline Wrap scopedEnum(YGWrap unscoped) {
return static_cast<Wrap>(unscoped); return static_cast<Wrap>(unscoped);
} }
constexpr inline YGWrap unscopedEnum(Wrap scoped) { constexpr YGWrap unscopedEnum(Wrap scoped) {
return static_cast<YGWrap>(scoped); return static_cast<YGWrap>(scoped);
} }

View File

@@ -7,25 +7,44 @@
#pragma once #pragma once
#include <bit>
#include <iterator> #include <iterator>
#include <type_traits> #include <type_traits>
namespace facebook::yoga { namespace facebook::yoga {
/**
* Concept for any enum/enum class
*/
template <typename EnumT> template <typename EnumT>
constexpr inline int32_t ordinalCount(); concept Enumeration = std::is_enum_v<EnumT>;
/**
* Count of ordinals in a Yoga enum which is sequential
*/
template <Enumeration EnumT>
constexpr int32_t ordinalCount();
/**
* Concept for a yoga enum which is sequential
*/
template <typename EnumT>
concept HasOrdinality = (ordinalCount<EnumT>() > 0);
/** /**
* Count of bits needed to represent every ordinal * Count of bits needed to represent every ordinal
*/ */
template <typename EnumT> template <HasOrdinality EnumT>
constexpr inline int32_t bitCount(); constexpr int32_t bitCount() {
return std::bit_width(
static_cast<std::underlying_type_t<EnumT>>(ordinalCount<EnumT>() - 1));
}
/** /**
* Polyfill of C++ 23 to_underlying() * Polyfill of C++ 23 to_underlying()
* https://en.cppreference.com/w/cpp/utility/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<std::underlying_type_t<decltype(e)>>(e); return static_cast<std::underlying_type_t<decltype(e)>>(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 * Convenience function to iterate through every value in a Yoga enum as part of
* a range-based for loop. * a range-based for loop.
*/ */
template <typename EnumT> template <HasOrdinality EnumT>
auto ordinals() { auto ordinals() {
struct Iterator { struct Iterator {
EnumT e{}; EnumT e{};

View File

@@ -10,27 +10,32 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cmath> #include <cmath>
#include <concepts>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
namespace facebook::yoga { namespace facebook::yoga {
constexpr bool isUndefined(auto value) { constexpr bool isUndefined(std::floating_point auto value) {
return value != value; return value != value;
} }
constexpr bool isDefined(auto value) { constexpr bool isDefined(std::floating_point auto value) {
return !isUndefined(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)) { if (yoga::isDefined(a) && yoga::isDefined(b)) {
return std::max(a, b); return std::max(a, b);
} }
return yoga::isUndefined(a) ? b : a; 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)) { if (yoga::isDefined(a) && yoga::isDefined(b)) {
return std::min(a, b); return std::min(a, b);
} }

View File

@@ -7,6 +7,7 @@
#pragma once #pragma once
#include <bit>
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
@@ -14,7 +15,6 @@
#include <yoga/YGMacros.h> #include <yoga/YGMacros.h>
#include <yoga/YGValue.h> #include <yoga/YGValue.h>
#include <yoga/bits/BitCast.h>
#include <yoga/numeric/Comparison.h> #include <yoga/numeric/Comparison.h>
static_assert( static_assert(
@@ -69,7 +69,7 @@ class YG_EXPORT CompactValue {
} }
uint32_t unitBit = Unit == YGUnitPercent ? PERCENT_BIT : 0; uint32_t unitBit = Unit == YGUnitPercent ? PERCENT_BIT : 0;
auto data = yoga::bit_cast<uint32_t>(value); auto data = std::bit_cast<uint32_t>(value);
data -= BIAS; data -= BIAS;
data |= unitBit; data |= unitBit;
return {data}; return {data};
@@ -112,7 +112,7 @@ class YG_EXPORT CompactValue {
return YGValue{0.0f, YGUnitPercent}; return YGValue{0.0f, YGUnitPercent};
} }
if (std::isnan(yoga::bit_cast<float>(repr_))) { if (std::isnan(std::bit_cast<float>(repr_))) {
return YGValueUndefined; return YGValueUndefined;
} }
@@ -121,14 +121,14 @@ class YG_EXPORT CompactValue {
data += BIAS; data += BIAS;
return YGValue{ return YGValue{
yoga::bit_cast<float>(data), std::bit_cast<float>(data),
repr_ & 0x40000000 ? YGUnitPercent : YGUnitPoint}; repr_ & 0x40000000 ? YGUnitPercent : YGUnitPoint};
} }
bool isUndefined() const noexcept { bool isUndefined() const noexcept {
return ( return (
repr_ != AUTO_BITS && repr_ != ZERO_BITS_POINT && repr_ != AUTO_BITS && repr_ != ZERO_BITS_POINT &&
repr_ != ZERO_BITS_PERCENT && std::isnan(yoga::bit_cast<float>(repr_))); repr_ != ZERO_BITS_PERCENT && std::isnan(std::bit_cast<float>(repr_)));
} }
bool isDefined() const noexcept { bool isDefined() const noexcept {