diff options
author | Abseil Team <absl-team@google.com> | 2024-07-01 11:33:54 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-07-01 11:34:46 -0700 |
commit | 37ebde53cfcf400ef01b59c80ae3f72039cd90f2 (patch) | |
tree | 1977c5d4878e02cdaa96ed831f775e47bbd58f57 /absl/base | |
parent | a27662352e9caafc264747562162a8a32ef36cb9 (diff) | |
download | abseil-37ebde53cfcf400ef01b59c80ae3f72039cd90f2.tar.gz abseil-37ebde53cfcf400ef01b59c80ae3f72039cd90f2.tar.bz2 abseil-37ebde53cfcf400ef01b59c80ae3f72039cd90f2.zip |
Make c_begin, c_end, and c_distance conditionally constexpr.
This allows them to be used in constexpr expressions, such as the following:
```
constexpr int distance = absl::c_distance(std::array<int, 3>());
```
Requires at least C++17 to be constexpr.
PiperOrigin-RevId: 648435141
Change-Id: I8136e351a6dc4c25f06ef895fb449f4f11048480
Diffstat (limited to 'absl/base')
-rw-r--r-- | absl/base/config.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/absl/base/config.h b/absl/base/config.h index a8f2eab5..13263f9d 100644 --- a/absl/base/config.h +++ b/absl/base/config.h @@ -941,6 +941,27 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || #define ABSL_HAVE_CONSTANT_EVALUATED 1 #endif +// ABSL_CONSTEXPR_SINCE_CXXYY is used to conditionally define constexpr for +// different C++ versions. +#if defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ + ABSL_INTERNAL_CPLUSPLUS_LANG >= 201402L +#define ABSL_CONSTEXPR_SINCE_CXX14 constexpr +#else +#define ABSL_CONSTEXPR_SINCE_CXX14 +#endif +#if defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ + ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L +#define ABSL_CONSTEXPR_SINCE_CXX17 constexpr +#else +#define ABSL_CONSTEXPR_SINCE_CXX17 +#endif +#if defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ + ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L +#define ABSL_CONSTEXPR_SINCE_CXX20 constexpr +#else +#define ABSL_CONSTEXPR_SINCE_CXX20 +#endif + // ABSL_INTERNAL_EMSCRIPTEN_VERSION combines Emscripten's three version macros // into an integer that can be compared against. #ifdef ABSL_INTERNAL_EMSCRIPTEN_VERSION |