Skip to content

Commit

Permalink
Breaking: Use C++ 20
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#39437

Have been running into places where C++ 20 makes life easier for use like `std::bit_cast` (that one is easy to polyfill), in-class member initializer support for bitfields, designated initializers, defaulted comparison operator, concepts instead of SFINAE, and probably more.

Our other infra is in the process of making this jump, or already has. This tests it out everywhere, across the various reference builds, to see if we have any issues.

This is a bit more aggressive than I had previously, but n - 1 is going to be a better long term place than n - 2. I think it is likely everything will be buildable for a while under Clang 10 (released 3.5 years ago), GCC 10 (releaseed 3.5 years ago), and VS 16.11 (released 2 years ago).

Differential Revision: D49261607
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 14, 2023
1 parent f9c2c27 commit ade44a5
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ let package = Package(
]
)
],
cxxLanguageStandard: CXXLanguageStandard(rawValue: "c++17")
cxxLanguageStandard: CXXLanguageStandard(rawValue: "c++20")
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yoga is an embeddable and performant flexbox layout engine with bindings for mul


## Building
Yoga's main implementation targets C++ 17 with accompanying build logic in CMake. A wrapper is provided to build the main library and run unit tests.
Yoga's main implementation targets C++ 20 with accompanying build logic in CMake. A wrapper is provided to build the main library and run unit tests.

```sh
./unit_tests <Debug|Release>
Expand Down
2 changes: 1 addition & 1 deletion Yoga.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Pod::Spec.new do |spec|
'-Werror',
'-Wextra',
'-Wconversion',
'-std=c++17',
'-std=c++20',
'-fPIC'
]

Expand Down
2 changes: 1 addition & 1 deletion cmake/project-defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Expand Down
15 changes: 8 additions & 7 deletions java/jni/YGJNIVanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
* LICENSE file in the root directory of this source tree.
*/

#include "YGJNIVanilla.h"
#include <bit>
#include <cstring>
#include <iostream>
#include <memory>

#include <jni.h>
#include <yoga/Yoga-internal.h>

#include "LayoutContext.h"
#include "YGJNI.h"
#include "YGJNIVanilla.h"
#include "YGJTypesVanilla.h"
#include "YogaJniException.h"
#include "common.h"
#include "jni.h"

#include <yoga/Yoga-internal.h>
#include <yoga/bits/BitCast.h>

using namespace facebook;
using namespace facebook::yoga;
Expand Down Expand Up @@ -645,8 +646,8 @@ static YGSize YGJNIMeasureFunc(
uint32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
uint32_t hBits = 0xFFFFFFFF & measureResult;

const float measuredWidth = yoga::bit_cast<float>(wBits);
const float measuredHeight = yoga::bit_cast<float>(hBits);
const float measuredWidth = std::bit_cast<float>(wBits);
const float measuredHeight = std::bit_cast<float>(hBits);

return YGSize{measuredWidth, measuredHeight};
} else {
Expand Down
2 changes: 1 addition & 1 deletion javascript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ file(GLOB SOURCES CONFIGURE_DEPENDS

include_directories(..)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

add_compile_definitions(
EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0)
Expand Down
29 changes: 0 additions & 29 deletions yoga/bits/BitCast.h

This file was deleted.

11 changes: 5 additions & 6 deletions yoga/style/CompactValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

#pragma once

#include <bit>
#include <cmath>
#include <cstdint>
#include <limits>

#include <yoga/YGMacros.h>
#include <yoga/YGValue.h>

#include <yoga/bits/BitCast.h>

static_assert(
std::numeric_limits<float>::is_iec559,
"facebook::yoga::detail::CompactValue only works with IEEE754 floats");
Expand Down Expand Up @@ -64,7 +63,7 @@ class YG_EXPORT CompactValue {
}

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 |= unitBit;
return {data};
Expand Down Expand Up @@ -117,7 +116,7 @@ class YG_EXPORT CompactValue {
return YGValue{0.0f, YGUnitPercent};
}

if (std::isnan(yoga::bit_cast<float>(repr_))) {
if (std::isnan(std::bit_cast<float>(repr_))) {
return YGValueUndefined;
}

Expand All @@ -126,14 +125,14 @@ class YG_EXPORT CompactValue {
data += BIAS;

return YGValue{
yoga::bit_cast<float>(data),
std::bit_cast<float>(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<float>(repr_)));
repr_ != ZERO_BITS_PERCENT && std::isnan(std::bit_cast<float>(repr_)));
}

bool isAuto() const noexcept {
Expand Down

0 comments on commit ade44a5

Please sign in to comment.