summaryrefslogtreecommitdiff
path: root/absl/types
diff options
context:
space:
mode:
authorGravatar Marcin Kowalczyk <qrczak@google.com>2023-12-05 08:47:14 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-12-05 08:48:09 -0800
commitf845e60acd880dbf07788a5a2c0dbad0f9c57231 (patch)
tree004d2977ebac75185dc68e0e675a5fc6ef118ea0 /absl/types
parent7b6c17e378224844d8663a410da2da5353b205b9 (diff)
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
Diffstat (limited to 'absl/types')
-rw-r--r--absl/types/BUILD.bazel1
-rw-r--r--absl/types/CMakeLists.txt1
-rw-r--r--absl/types/compare.h24
3 files changed, 26 insertions, 0 deletions
diff --git a/absl/types/BUILD.bazel b/absl/types/BUILD.bazel
index 3d5cf012..31a5daa2 100644
--- a/absl/types/BUILD.bazel
+++ b/absl/types/BUILD.bazel
@@ -293,6 +293,7 @@ cc_library(
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
+ "//absl/base:config",
"//absl/base:core_headers",
"//absl/meta:type_traits",
],
diff --git a/absl/types/CMakeLists.txt b/absl/types/CMakeLists.txt
index 1adf3c72..024c2c39 100644
--- a/absl/types/CMakeLists.txt
+++ b/absl/types/CMakeLists.txt
@@ -284,6 +284,7 @@ absl_cc_library(
COPTS
${ABSL_DEFAULT_COPTS}
DEPS
+ absl::config
absl::core_headers
absl::type_traits
PUBLIC
diff --git a/absl/types/compare.h b/absl/types/compare.h
index ab0543c0..3cf4a917 100644
--- a/absl/types/compare.h
+++ b/absl/types/compare.h
@@ -30,6 +30,17 @@
#ifndef ABSL_TYPES_COMPARE_H_
#define ABSL_TYPES_COMPARE_H_
+#include "absl/base/config.h"
+
+#ifdef ABSL_USES_STD_ORDERING
+
+#include <compare> // IWYU pragma: export
+#include <type_traits>
+
+#include "absl/meta/type_traits.h"
+
+#else
+
#include <cstddef>
#include <cstdint>
#include <cstdlib>
@@ -39,8 +50,19 @@
#include "absl/base/macros.h"
#include "absl/meta/type_traits.h"
+#endif
+
namespace absl {
ABSL_NAMESPACE_BEGIN
+
+#ifdef ABSL_USES_STD_ORDERING
+
+using std::partial_ordering;
+using std::strong_ordering;
+using std::weak_ordering;
+
+#else
+
namespace compare_internal {
using value_type = int8_t;
@@ -419,6 +441,8 @@ ABSL_COMPARE_INLINE_INIT(strong_ordering, greater,
#undef ABSL_COMPARE_INLINE_SUBCLASS_DECL
#undef ABSL_COMPARE_INLINE_INIT
+#endif // ABSL_USES_STD_ORDERING
+
namespace compare_internal {
// We also provide these comparator adapter functions for internal absl use.