Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mpusz/units
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Dec 28, 2024
2 parents 0948840 + ba6e19d commit 146d7a3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 41 deletions.
20 changes: 15 additions & 5 deletions .github/generate-job-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,20 @@ def make_clang_config(
return Configuration(**vars(ret))


def make_apple_clang_config(version: int) -> Configuration:
def make_apple_clang_config(
os: str, version: str, std_format_support: bool
) -> Configuration:
ret = Configuration(
name=f"Apple Clang {version}",
os="macos-13",
os=os,
compiler=Compiler(
type="APPLE_CLANG",
version=f"{version}.0",
version=version,
cc="clang",
cxx="clang++",
),
cxx_modules=False,
std_format_support=False,
std_format_support=std_format_support,
)
return ret

Expand Down Expand Up @@ -95,7 +97,15 @@ def make_msvc_config(release: str, version: int) -> Configuration:
# arm64 runners are expensive; only consider one version
if ver == 18 or platform != "arm64"
]
+ [make_apple_clang_config(ver) for ver in [15]]
+ [
make_apple_clang_config("macos-13", ver, std_format_support=False)
for ver in ["15.2"]
]
# std::format is available in Xcode 16.1 or later
+ [
make_apple_clang_config("macos-14", ver, std_format_support=True)
for ver in ["16.1"]
]
+ [make_msvc_config(release="14.4", version=194)]
}

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ CMakeUserPresets.json
# cxxdraft-htmlgen
docs/api_reference/src/source/
docs/api_reference/gen

# macOS files
.DS_Store
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _feature_compatibility(self):
"compiler": {
"gcc": "13",
"clang": "17",
"apple-clang": "",
"apple-clang": "16",
"msvc": "194",
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started/cpp_compiler_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ C++ feature:
| C++ Feature | C++ version | gcc | clang | apple-clang | MSVC |
|-----------------------------------------------------------|:-----------:|:----:|:-----:|:-----------:|:-----------------------------------------:|
| **Minimum support** | 20 | 12 | 16 | 15 | 194 :bug:{ title="BEWARE of MSVC Bugs!" } |
| **`std::format`** | 20 | 13 | 17 | None | 194 |
| **`std::format`** | 20 | 13 | 17 | 16 | 194 |
| **C++ modules** | 20 | None | 17 | None | None |
| **`import std;`** | 23 | None | 18 | None | None |
| **Explicit `this` parameter** | 23 | 14 | 18 | None | None |
Expand Down
16 changes: 9 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ check_cxx_feature_supported(__cpp_explicit_this_parameter ${projectPrefix}EXPLIC

# libc++ has a basic supports for std::format but does not set __cpp_lib_format
# https://github.com/llvm/llvm-project/issues/77773
if(NOT ${projectPrefix}LIB_FORMAT_SUPPORTED
AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17"
AND ${projectPrefix}LIBCXX
)
message(STATUS "Clang 17+ with libc++ detected, overriding `std::format` support")
set(${projectPrefix}LIB_FORMAT_SUPPORTED ON)
if(NOT ${projectPrefix}LIB_FORMAT_SUPPORTED AND ${projectPrefix}LIBCXX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
message(STATUS "Clang 17+ with libc++ detected, overriding `std::format` support")
set(${projectPrefix}LIB_FORMAT_SUPPORTED ON)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "16")
message(STATUS "AppleClang 16+ with libc++ detected, overriding `std::format` support")
set(${projectPrefix}LIB_FORMAT_SUPPORTED ON)
endif()
endif()

# clang++-18 supports explicit `this` parameter
Expand Down
4 changes: 4 additions & 0 deletions src/core/include/mp-units/bits/hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,9 @@ MP_UNITS_DIAGNOSTIC_POP

#define MP_UNITS_API_NO_CRTP 1

#endif

#if defined(__clang__) && defined(__apple_build_version__) && __apple_build_version__ < 16000026
#define MP_UNITS_XCODE15_HACKS
#endif
// NOLINTEND(bugprone-reserved-identifier, cppcoreguidelines-macro-usage)
63 changes: 36 additions & 27 deletions src/core/include/mp-units/framework/representation_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ concept Scalar = (!disable_scalar<T>) &&
{ a + b } -> std::common_with<T>;
{ a - b } -> std::common_with<T>;
} && ScalableWith<T, T>
#if MP_UNITS_COMP_GCC != 12
#if MP_UNITS_COMP_GCC != 12 && !defined(MP_UNITS_XCODE15_HACKS)
&& WeaklyRegular<T>
#endif
;
Expand Down Expand Up @@ -177,19 +177,23 @@ constexpr bool disable_complex = false;
namespace detail {

template<typename T>
concept Complex = (!disable_complex<T>) && requires(const T a, const T b, const T& c) {
{ -a } -> std::common_with<T>;
{ a + b } -> std::common_with<T>;
{ a - b } -> std::common_with<T>;
{ a* b } -> std::common_with<T>;
{ a / b } -> std::common_with<T>;
::mp_units::real(a);
::mp_units::imag(a);
::mp_units::modulus(a);
requires ScalableWith<T, decltype(::mp_units::modulus(a))>;
requires std::constructible_from<T, decltype(::mp_units::real(c)), decltype(::mp_units::imag(c))>;
} && WeaklyRegular<T>;

concept Complex = (!disable_complex<T>) &&
requires(const T a, const T b, const T& c) {
{ -a } -> std::common_with<T>;
{ a + b } -> std::common_with<T>;
{ a - b } -> std::common_with<T>;
{ a* b } -> std::common_with<T>;
{ a / b } -> std::common_with<T>;
::mp_units::real(a);
::mp_units::imag(a);
::mp_units::modulus(a);
requires ScalableWith<T, decltype(::mp_units::modulus(a))>;
requires std::constructible_from<T, decltype(::mp_units::real(c)), decltype(::mp_units::imag(c))>;
}
#ifndef MP_UNITS_XCODE15_HACKS
&& WeaklyRegular<T>
#endif
;
namespace magnitude_impl {

void magnitude() = delete; // poison pill
Expand Down Expand Up @@ -238,19 +242,24 @@ constexpr bool disable_vector = false;
namespace detail {

template<typename T>
concept Vector = (!disable_vector<T>) && requires(const T a, const T b) {
{ -a } -> std::common_with<T>;
{ a + b } -> std::common_with<T>;
{ a - b } -> std::common_with<T>;
::mp_units::magnitude(a);
requires ScalableWith<T, decltype(::mp_units::magnitude(a))>;
// TODO should we also check for the below (e.g., when `size() > 1` or `2`)
// ::mp_units::zero_vector<T>();
// ::mp_units::unit_vector(a);
// ::mp_units::scalar_product(a, b);
// ::mp_units::vector_product(a, b);
// ::mp_units::tensor_product(a, b);
} && WeaklyRegular<T>;
concept Vector = (!disable_vector<T>) &&
requires(const T a, const T b) {
{ -a } -> std::common_with<T>;
{ a + b } -> std::common_with<T>;
{ a - b } -> std::common_with<T>;
::mp_units::magnitude(a);
requires ScalableWith<T, decltype(::mp_units::magnitude(a))>;
// TODO should we also check for the below (e.g., when `size() > 1` or `2`)
// ::mp_units::zero_vector<T>();
// ::mp_units::unit_vector(a);
// ::mp_units::scalar_product(a, b);
// ::mp_units::vector_product(a, b);
// ::mp_units::tensor_product(a, b);
}
#ifndef MP_UNITS_XCODE15_HACKS
&& WeaklyRegular<T>
#endif
;

} // namespace detail

Expand Down

0 comments on commit 146d7a3

Please sign in to comment.