From f845e60acd880dbf07788a5a2c0dbad0f9c57231 Mon Sep 17 00:00:00 2001 From: Marcin Kowalczyk Date: Tue, 5 Dec 2023 08:47:14 -0800 Subject: Make `absl::{partial,weak,strong}_ordering` aliases for the `std::` ordering types when they are available. This makes them interchangeable in contexts known to be compiled as C++20. This also makes `absl::` ordering types compatible with `<=>`, allowing to unconditionally use `absl::` spelling for types but conditionally use `<=>` when available. PiperOrigin-RevId: 588085408 Change-Id: I1aa5247f0e31acbb838ee76829b7a13c74b0a94f --- absl/base/config.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'absl/base/config.h') diff --git a/absl/base/config.h b/absl/base/config.h index b0e7fe8b..0fb66927 100644 --- a/absl/base/config.h +++ b/absl/base/config.h @@ -609,6 +609,22 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || #define ABSL_HAVE_STD_STRING_VIEW 1 #endif +// ABSL_HAVE_STD_ORDERING +// +// Checks whether C++20 std::{partial,weak,strong}_ordering are available. +// +// __cpp_lib_three_way_comparison is missing on libc++ +// (https://github.com/llvm/llvm-project/issues/73953) so treat it as defined +// when building in C++20 mode. +#ifdef ABSL_HAVE_STD_ORDERING +#error "ABSL_HAVE_STD_ORDERING cannot be directly set." +#elif (defined(__cpp_lib_three_way_comparison) && \ + __cpp_lib_three_way_comparison >= 201907L) || \ + (defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ + ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L) +#define ABSL_HAVE_STD_ORDERING 1 +#endif + // ABSL_USES_STD_ANY // // Indicates whether absl::any is an alias for std::any. @@ -671,6 +687,22 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || #error options.h is misconfigured. #endif +// ABSL_USES_STD_ORDERING +// +// Indicates whether absl::{partial,weak,strong}_ordering are aliases for the +// std:: ordering types. +#if !defined(ABSL_OPTION_USE_STD_ORDERING) +#error options.h is misconfigured. +#elif ABSL_OPTION_USE_STD_ORDERING == 0 || \ + (ABSL_OPTION_USE_STD_ORDERING == 2 && !defined(ABSL_HAVE_STD_ORDERING)) +#undef ABSL_USES_STD_ORDERING +#elif ABSL_OPTION_USE_STD_ORDERING == 1 || \ + (ABSL_OPTION_USE_STD_ORDERING == 2 && defined(ABSL_HAVE_STD_ORDERING)) +#define ABSL_USES_STD_ORDERING 1 +#else +#error options.h is misconfigured. +#endif + // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION // SEH exception from emplace for variant when constructing the // struct can throw. This defeats some of variant_test and -- cgit v1.2.3