aboutsummaryrefslogtreecommitdiff
path: root/absl/strings/internal/string_constant.h
diff options
context:
space:
mode:
authorBenjamin Barenblat <bbaren@google.com>2022-07-12 21:47:19 -0400
committerBenjamin Barenblat <bbaren@google.com>2022-07-12 21:47:19 -0400
commitd055841ab4147dac20d5c46d04ca3a2fb13748b7 (patch)
tree15a01389c86f10a8844ff2a86bddf46640d065e8 /absl/strings/internal/string_constant.h
parent2d23a3e16abfcf8f22ba850d67e972cc77e98874 (diff)
parent273292d1cfc0a94a65082ee350509af1d113344d (diff)
downloadabseil-d055841ab4147dac20d5c46d04ca3a2fb13748b7.tar.gz
abseil-d055841ab4147dac20d5c46d04ca3a2fb13748b7.tar.bz2
abseil-d055841ab4147dac20d5c46d04ca3a2fb13748b7.zip
Merge new upstream LTS 20220623.0
Diffstat (limited to 'absl/strings/internal/string_constant.h')
-rw-r--r--absl/strings/internal/string_constant.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/absl/strings/internal/string_constant.h b/absl/strings/internal/string_constant.h
index a11336b7..f68b17d7 100644
--- a/absl/strings/internal/string_constant.h
+++ b/absl/strings/internal/string_constant.h
@@ -35,17 +35,25 @@ namespace strings_internal {
// below.
template <typename T>
struct StringConstant {
+ private:
+ static constexpr bool TryConstexprEval(absl::string_view view) {
+ return view.empty() || 2 * view[0] != 1;
+ }
+
+ public:
static constexpr absl::string_view value = T{}();
constexpr absl::string_view operator()() const { return value; }
// Check to be sure `view` points to constant data.
// Otherwise, it can't be constant evaluated.
- static_assert(value.empty() || 2 * value[0] != 1,
+ static_assert(TryConstexprEval(value),
"The input string_view must point to constant data.");
};
+#ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
template <typename T>
-constexpr absl::string_view StringConstant<T>::value; // NOLINT
+constexpr absl::string_view StringConstant<T>::value;
+#endif
// Factory function for `StringConstant` instances.
// It supports callables that have a constexpr default constructor and a