diff --git a/common/value.cc b/common/value.cc index ba1e86cbc..d42ceac30 100644 --- a/common/value.cc +++ b/common/value.cc @@ -37,7 +37,6 @@ #include "absl/types/span.h" #include "absl/types/variant.h" #include "base/attribute.h" -#include "common/casting.h" #include "common/json.h" #include "common/optional_ref.h" #include "common/type.h" @@ -619,14 +618,6 @@ absl::optional Value::AsBool() const { return absl::nullopt; } -optional_ref Value::AsBytes() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsBytes() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -667,14 +658,6 @@ absl::optional Value::AsDuration() const { return absl::nullopt; } -optional_ref Value::AsError() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsError() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -707,28 +690,6 @@ absl::optional Value::AsInt() const { return absl::nullopt; } -absl::optional Value::AsList() & { - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - absl::optional Value::AsList() const& { if (const auto* alternative = absl::get_if(&variant_); @@ -793,27 +754,6 @@ absl::optional Value::AsList() const&& { return absl::nullopt; } -absl::optional Value::AsMap() & { - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - absl::optional Value::AsMap() const& { if (const auto* alternative = absl::get_if(&variant_); @@ -877,14 +817,6 @@ absl::optional Value::AsMap() const&& { return absl::nullopt; } -absl::optional Value::AsMessage() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - absl::optional Value::AsMessage() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -917,14 +849,6 @@ absl::optional Value::AsNull() const { return absl::nullopt; } -optional_ref Value::AsOpaque() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsOpaque() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -949,14 +873,6 @@ absl::optional Value::AsOpaque() const&& { return absl::nullopt; } -optional_ref Value::AsOptional() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr && alternative->IsOptional()) { - return static_cast(*alternative); - } - return absl::nullopt; -} - optional_ref Value::AsOptional() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr && alternative->IsOptional()) { @@ -981,14 +897,6 @@ absl::optional Value::AsOptional() const&& { return absl::nullopt; } -optional_ref Value::AsParsedJsonList() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsParsedJsonList() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1013,14 +921,6 @@ absl::optional Value::AsParsedJsonList() const&& { return absl::nullopt; } -optional_ref Value::AsParsedJsonMap() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsParsedJsonMap() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1045,14 +945,6 @@ absl::optional Value::AsParsedJsonMap() const&& { return absl::nullopt; } -optional_ref Value::AsParsedList() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsParsedList() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1077,14 +969,6 @@ absl::optional Value::AsParsedList() const&& { return absl::nullopt; } -optional_ref Value::AsParsedMap() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsParsedMap() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1109,14 +993,6 @@ absl::optional Value::AsParsedMap() const&& { return absl::nullopt; } -optional_ref Value::AsParsedMapField() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsParsedMapField() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1141,14 +1017,6 @@ absl::optional Value::AsParsedMapField() const&& { return absl::nullopt; } -optional_ref Value::AsParsedMessage() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsParsedMessage() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1173,15 +1041,6 @@ absl::optional Value::AsParsedMessage() const&& { return absl::nullopt; } -optional_ref Value::AsParsedRepeatedField() & { - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsParsedRepeatedField() const& { if (const auto* alternative = @@ -1209,14 +1068,6 @@ absl::optional Value::AsParsedRepeatedField() return absl::nullopt; } -optional_ref Value::AsParsedStruct() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsParsedStruct() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1241,14 +1092,6 @@ absl::optional Value::AsParsedStruct() const&& { return absl::nullopt; } -optional_ref Value::AsString() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsString() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1273,23 +1116,6 @@ absl::optional Value::AsString() const&& { return absl::nullopt; } -absl::optional Value::AsStruct() & { - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - absl::optional Value::AsStruct() const& { if (const auto* alternative = absl::get_if(&variant_); @@ -1349,14 +1175,6 @@ absl::optional Value::AsTimestamp() const { return absl::nullopt; } -optional_ref Value::AsType() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsType() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1389,14 +1207,6 @@ absl::optional Value::AsUint() const { return absl::nullopt; } -optional_ref Value::AsUnknown() & { - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - return absl::nullopt; -} - optional_ref Value::AsUnknown() const& { if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { @@ -1426,11 +1236,6 @@ BoolValue Value::GetBool() const { return absl::get(variant_); } -const BytesValue& Value::GetBytes() & { - ABSL_DCHECK(IsBytes()) << *this; - return absl::get(variant_); -} - const BytesValue& Value::GetBytes() const& { ABSL_DCHECK(IsBytes()) << *this; return absl::get(variant_); @@ -1456,11 +1261,6 @@ DurationValue Value::GetDuration() const { return absl::get(variant_); } -const ErrorValue& Value::GetError() & { - ABSL_DCHECK(IsError()) << *this; - return absl::get(variant_); -} - const ErrorValue& Value::GetError() const& { ABSL_DCHECK(IsError()) << *this; return absl::get(variant_); @@ -1488,29 +1288,6 @@ IntValue Value::GetInt() const { ABSL_LOG(FATAL) << absl::bad_variant_access().what() /* Crash OK */ #endif -ListValue Value::GetList() & { - ABSL_DCHECK(IsList()) << *this; - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - CEL_VALUE_THROW_BAD_VARIANT_ACCESS(); -} - ListValue Value::GetList() const& { ABSL_DCHECK(IsList()) << *this; if (const auto* alternative = @@ -1578,28 +1355,6 @@ ListValue Value::GetList() const&& { CEL_VALUE_THROW_BAD_VARIANT_ACCESS(); } -MapValue Value::GetMap() & { - ABSL_DCHECK(IsMap()) << *this; - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - CEL_VALUE_THROW_BAD_VARIANT_ACCESS(); -} - MapValue Value::GetMap() const& { ABSL_DCHECK(IsMap()) << *this; if (const auto* alternative = @@ -1666,11 +1421,6 @@ MapValue Value::GetMap() const&& { CEL_VALUE_THROW_BAD_VARIANT_ACCESS(); } -MessageValue Value::GetMessage() & { - ABSL_DCHECK(IsMessage()) << *this; - return absl::get(variant_); -} - MessageValue Value::GetMessage() const& { ABSL_DCHECK(IsMessage()) << *this; return absl::get(variant_); @@ -1691,11 +1441,6 @@ NullValue Value::GetNull() const { return absl::get(variant_); } -const OpaqueValue& Value::GetOpaque() & { - ABSL_DCHECK(IsOpaque()) << *this; - return absl::get(variant_); -} - const OpaqueValue& Value::GetOpaque() const& { ABSL_DCHECK(IsOpaque()) << *this; return absl::get(variant_); @@ -1711,11 +1456,6 @@ OpaqueValue Value::GetOpaque() const&& { return absl::get(std::move(variant_)); } -const OptionalValue& Value::GetOptional() & { - ABSL_DCHECK(IsOptional()) << *this; - return static_cast(absl::get(variant_)); -} - const OptionalValue& Value::GetOptional() const& { ABSL_DCHECK(IsOptional()) << *this; return static_cast(absl::get(variant_)); @@ -1733,11 +1473,6 @@ OptionalValue Value::GetOptional() const&& { absl::get(std::move(variant_))); } -const ParsedJsonListValue& Value::GetParsedJsonList() & { - ABSL_DCHECK(IsParsedJsonList()) << *this; - return absl::get(variant_); -} - const ParsedJsonListValue& Value::GetParsedJsonList() const& { ABSL_DCHECK(IsParsedJsonList()) << *this; return absl::get(variant_); @@ -1753,11 +1488,6 @@ ParsedJsonListValue Value::GetParsedJsonList() const&& { return absl::get(std::move(variant_)); } -const ParsedJsonMapValue& Value::GetParsedJsonMap() & { - ABSL_DCHECK(IsParsedJsonMap()) << *this; - return absl::get(variant_); -} - const ParsedJsonMapValue& Value::GetParsedJsonMap() const& { ABSL_DCHECK(IsParsedJsonMap()) << *this; return absl::get(variant_); @@ -1773,11 +1503,6 @@ ParsedJsonMapValue Value::GetParsedJsonMap() const&& { return absl::get(std::move(variant_)); } -const ParsedListValue& Value::GetParsedList() & { - ABSL_DCHECK(IsParsedList()) << *this; - return absl::get(variant_); -} - const ParsedListValue& Value::GetParsedList() const& { ABSL_DCHECK(IsParsedList()) << *this; return absl::get(variant_); @@ -1793,11 +1518,6 @@ ParsedListValue Value::GetParsedList() const&& { return absl::get(std::move(variant_)); } -const ParsedMapValue& Value::GetParsedMap() & { - ABSL_DCHECK(IsParsedMap()) << *this; - return absl::get(variant_); -} - const ParsedMapValue& Value::GetParsedMap() const& { ABSL_DCHECK(IsParsedMap()) << *this; return absl::get(variant_); @@ -1813,11 +1533,6 @@ ParsedMapValue Value::GetParsedMap() const&& { return absl::get(std::move(variant_)); } -const ParsedMapFieldValue& Value::GetParsedMapField() & { - ABSL_DCHECK(IsParsedMapField()) << *this; - return absl::get(variant_); -} - const ParsedMapFieldValue& Value::GetParsedMapField() const& { ABSL_DCHECK(IsParsedMapField()) << *this; return absl::get(variant_); @@ -1833,11 +1548,6 @@ ParsedMapFieldValue Value::GetParsedMapField() const&& { return absl::get(std::move(variant_)); } -const ParsedMessageValue& Value::GetParsedMessage() & { - ABSL_DCHECK(IsParsedMessage()) << *this; - return absl::get(variant_); -} - const ParsedMessageValue& Value::GetParsedMessage() const& { ABSL_DCHECK(IsParsedMessage()) << *this; return absl::get(variant_); @@ -1853,11 +1563,6 @@ ParsedMessageValue Value::GetParsedMessage() const&& { return absl::get(std::move(variant_)); } -const ParsedRepeatedFieldValue& Value::GetParsedRepeatedField() & { - ABSL_DCHECK(IsParsedRepeatedField()) << *this; - return absl::get(variant_); -} - const ParsedRepeatedFieldValue& Value::GetParsedRepeatedField() const& { ABSL_DCHECK(IsParsedRepeatedField()) << *this; return absl::get(variant_); @@ -1873,11 +1578,6 @@ ParsedRepeatedFieldValue Value::GetParsedRepeatedField() const&& { return absl::get(std::move(variant_)); } -const ParsedStructValue& Value::GetParsedStruct() & { - ABSL_DCHECK(IsParsedMap()) << *this; - return absl::get(variant_); -} - const ParsedStructValue& Value::GetParsedStruct() const& { ABSL_DCHECK(IsParsedMap()) << *this; return absl::get(variant_); @@ -1893,11 +1593,6 @@ ParsedStructValue Value::GetParsedStruct() const&& { return absl::get(std::move(variant_)); } -const StringValue& Value::GetString() & { - ABSL_DCHECK(IsString()) << *this; - return absl::get(variant_); -} - const StringValue& Value::GetString() const& { ABSL_DCHECK(IsString()) << *this; return absl::get(variant_); @@ -1913,24 +1608,6 @@ StringValue Value::GetString() const&& { return absl::get(std::move(variant_)); } -StructValue Value::GetStruct() & { - ABSL_DCHECK(IsStruct()) << *this; - if (const auto* alternative = - absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - if (const auto* alternative = absl::get_if(&variant_); - alternative != nullptr) { - return *alternative; - } - CEL_VALUE_THROW_BAD_VARIANT_ACCESS(); -} - StructValue Value::GetStruct() const& { ABSL_DCHECK(IsStruct()) << *this; if (const auto* alternative = @@ -1990,11 +1667,6 @@ TimestampValue Value::GetTimestamp() const { return absl::get(variant_); } -const TypeValue& Value::GetType() & { - ABSL_DCHECK(IsType()) << *this; - return absl::get(variant_); -} - const TypeValue& Value::GetType() const& { ABSL_DCHECK(IsType()) << *this; return absl::get(variant_); @@ -2015,11 +1687,6 @@ UintValue Value::GetUint() const { return absl::get(variant_); } -const UnknownValue& Value::GetUnknown() & { - ABSL_DCHECK(IsUnknown()) << *this; - return absl::get(variant_); -} - const UnknownValue& Value::GetUnknown() const& { ABSL_DCHECK(IsUnknown()) << *this; return absl::get(variant_); diff --git a/common/value.h b/common/value.h index 0f4f8b261..0132869fe 100644 --- a/common/value.h +++ b/common/value.h @@ -700,7 +700,9 @@ class Value final { // Performs a checked cast from a value to a bytes value, // returning a non-empty optional with either a value or reference to the // bytes value. Otherwise an empty optional is returned. - optional_ref AsBytes() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + optional_ref AsBytes() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsBytes(); + } optional_ref AsBytes() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsBytes() &&; absl::optional AsBytes() const&&; @@ -718,7 +720,9 @@ class Value final { // Performs a checked cast from a value to an error value, // returning a non-empty optional with either a value or reference to the // error value. Otherwise an empty optional is returned. - optional_ref AsError() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + optional_ref AsError() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsError(); + } optional_ref AsError() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsError() &&; absl::optional AsError() const&&; @@ -731,7 +735,7 @@ class Value final { // Performs a checked cast from a value to a list value, // returning a non-empty optional with either a value or reference to the // list value. Otherwise an empty optional is returned. - absl::optional AsList() &; + absl::optional AsList() & { return std::as_const(*this).AsList(); } absl::optional AsList() const&; absl::optional AsList() &&; absl::optional AsList() const&&; @@ -739,7 +743,7 @@ class Value final { // Performs a checked cast from a value to a map value, // returning a non-empty optional with either a value or reference to the // map value. Otherwise an empty optional is returned. - absl::optional AsMap() &; + absl::optional AsMap() & { return std::as_const(*this).AsMap(); } absl::optional AsMap() const&; absl::optional AsMap() &&; absl::optional AsMap() const&&; @@ -747,7 +751,9 @@ class Value final { // Performs a checked cast from a value to a message value, // returning a non-empty optional with either a value or reference to the // message value. Otherwise an empty optional is returned. - absl::optional AsMessage() &; + absl::optional AsMessage() & { + return std::as_const(*this).AsMessage(); + } absl::optional AsMessage() const&; absl::optional AsMessage() &&; absl::optional AsMessage() const&&; @@ -760,7 +766,9 @@ class Value final { // Performs a checked cast from a value to an opaque value, // returning a non-empty optional with either a value or reference to the // opaque value. Otherwise an empty optional is returned. - optional_ref AsOpaque() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + optional_ref AsOpaque() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsOpaque(); + } optional_ref AsOpaque() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsOpaque() &&; @@ -770,7 +778,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // optional value. Otherwise an empty optional is returned. optional_ref AsOptional() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsOptional(); + } optional_ref AsOptional() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsOptional() &&; @@ -780,7 +790,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // parsed message value. Otherwise an empty optional is returned. optional_ref AsParsedJsonList() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsParsedJsonList(); + } optional_ref AsParsedJsonList() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsParsedJsonList() &&; @@ -790,7 +802,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // parsed message value. Otherwise an empty optional is returned. optional_ref AsParsedJsonMap() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsParsedJsonMap(); + } optional_ref AsParsedJsonMap() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsParsedJsonMap() &&; @@ -800,7 +814,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // parsed list value. Otherwise an empty optional is returned. optional_ref AsParsedList() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsParsedList(); + } optional_ref AsParsedList() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsParsedList() &&; @@ -810,7 +826,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // parsed map value. Otherwise an empty optional is returned. optional_ref AsParsedMap() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsParsedMap(); + } optional_ref AsParsedMap() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsParsedMap() &&; @@ -820,7 +838,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // parsed map field value. Otherwise an empty optional is returned. optional_ref AsParsedMapField() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsParsedMapField(); + } optional_ref AsParsedMapField() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsParsedMapField() &&; @@ -830,7 +850,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // parsed message value. Otherwise an empty optional is returned. optional_ref AsParsedMessage() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsParsedMessage(); + } optional_ref AsParsedMessage() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsParsedMessage() &&; @@ -840,7 +862,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // parsed repeated field value. Otherwise an empty optional is returned. optional_ref AsParsedRepeatedField() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsParsedRepeatedField(); + } optional_ref AsParsedRepeatedField() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsParsedRepeatedField() &&; @@ -850,7 +874,9 @@ class Value final { // returning a non-empty optional with either a value or reference to the // parsed struct value. Otherwise an empty optional is returned. optional_ref AsParsedStruct() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsParsedStruct(); + } optional_ref AsParsedStruct() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsParsedStruct() &&; @@ -859,7 +885,9 @@ class Value final { // Performs a checked cast from a value to a string value, // returning a non-empty optional with either a value or reference to the // string value. Otherwise an empty optional is returned. - optional_ref AsString() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + optional_ref AsString() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsString(); + } optional_ref AsString() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsString() &&; @@ -868,7 +896,9 @@ class Value final { // Performs a checked cast from a value to a struct value, // returning a non-empty optional with either a value or reference to the // struct value. Otherwise an empty optional is returned. - absl::optional AsStruct() &; + absl::optional AsStruct() & { + return std::as_const(*this).AsStruct(); + } absl::optional AsStruct() const&; absl::optional AsStruct() &&; absl::optional AsStruct() const&&; @@ -881,7 +911,9 @@ class Value final { // Performs a checked cast from a value to a type value, // returning a non-empty optional with either a value or reference to the // type value. Otherwise an empty optional is returned. - optional_ref AsType() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + optional_ref AsType() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsType(); + } optional_ref AsType() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsType() &&; absl::optional AsType() const&&; @@ -894,7 +926,9 @@ class Value final { // Performs a checked cast from a value to an unknown value, // returning a non-empty optional with either a value or reference to the // unknown value. Otherwise an empty optional is returned. - optional_ref AsUnknown() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + optional_ref AsUnknown() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).AsUnknown(); + } optional_ref AsUnknown() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; absl::optional AsUnknown() &&; @@ -1567,7 +1601,9 @@ class Value final { // Performs an unchecked cast from a value to a bytes value. In // debug builds a best effort is made to crash. If `IsBytes()` would return // false, calling this method is undefined behavior. - const BytesValue& GetBytes() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const BytesValue& GetBytes() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetBytes(); + } const BytesValue& GetBytes() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; BytesValue GetBytes() &&; BytesValue GetBytes() const&&; @@ -1585,7 +1621,9 @@ class Value final { // Performs an unchecked cast from a value to an error value. In // debug builds a best effort is made to crash. If `IsError()` would return // false, calling this method is undefined behavior. - const ErrorValue& GetError() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const ErrorValue& GetError() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetError(); + } const ErrorValue& GetError() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ErrorValue GetError() &&; ErrorValue GetError() const&&; @@ -1598,7 +1636,7 @@ class Value final { // Performs an unchecked cast from a value to a list value. In // debug builds a best effort is made to crash. If `IsList()` would return // false, calling this method is undefined behavior. - ListValue GetList() &; + ListValue GetList() & { return std::as_const(*this).GetList(); } ListValue GetList() const&; ListValue GetList() &&; ListValue GetList() const&&; @@ -1606,7 +1644,7 @@ class Value final { // Performs an unchecked cast from a value to a map value. In // debug builds a best effort is made to crash. If `IsMap()` would return // false, calling this method is undefined behavior. - MapValue GetMap() &; + MapValue GetMap() & { return std::as_const(*this).GetMap(); } MapValue GetMap() const&; MapValue GetMap() &&; MapValue GetMap() const&&; @@ -1614,7 +1652,7 @@ class Value final { // Performs an unchecked cast from a value to a message value. In // debug builds a best effort is made to crash. If `IsMessage()` would return // false, calling this method is undefined behavior. - MessageValue GetMessage() &; + MessageValue GetMessage() & { return std::as_const(*this).GetMessage(); } MessageValue GetMessage() const&; MessageValue GetMessage() &&; MessageValue GetMessage() const&&; @@ -1627,7 +1665,9 @@ class Value final { // Performs an unchecked cast from a value to an opaque value. In // debug builds a best effort is made to crash. If `IsOpaque()` would return // false, calling this method is undefined behavior. - const OpaqueValue& GetOpaque() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const OpaqueValue& GetOpaque() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetOpaque(); + } const OpaqueValue& GetOpaque() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; OpaqueValue GetOpaque() &&; OpaqueValue GetOpaque() const&&; @@ -1635,7 +1675,9 @@ class Value final { // Performs an unchecked cast from a value to an optional value. In // debug builds a best effort is made to crash. If `IsOptional()` would return // false, calling this method is undefined behavior. - const OptionalValue& GetOptional() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const OptionalValue& GetOptional() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetOptional(); + } const OptionalValue& GetOptional() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; OptionalValue GetOptional() &&; OptionalValue GetOptional() const&&; @@ -1644,7 +1686,9 @@ class Value final { // debug builds a best effort is made to crash. If `IsParsedJsonList()` would // return false, calling this method is undefined behavior. const ParsedJsonListValue& GetParsedJsonList() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetParsedJsonList(); + } const ParsedJsonListValue& GetParsedJsonList() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ParsedJsonListValue GetParsedJsonList() &&; @@ -1653,7 +1697,9 @@ class Value final { // Performs an unchecked cast from a value to a parsed message value. In // debug builds a best effort is made to crash. If `IsParsedJsonMap()` would // return false, calling this method is undefined behavior. - const ParsedJsonMapValue& GetParsedJsonMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const ParsedJsonMapValue& GetParsedJsonMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetParsedJsonMap(); + } const ParsedJsonMapValue& GetParsedJsonMap() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ParsedJsonMapValue GetParsedJsonMap() &&; @@ -1662,7 +1708,9 @@ class Value final { // Performs an unchecked cast from a value to a parsed list value. In // debug builds a best effort is made to crash. If `IsParsedList()` would // return false, calling this method is undefined behavior. - const ParsedListValue& GetParsedList() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const ParsedListValue& GetParsedList() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetParsedList(); + } const ParsedListValue& GetParsedList() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ParsedListValue GetParsedList() &&; ParsedListValue GetParsedList() const&&; @@ -1670,7 +1718,9 @@ class Value final { // Performs an unchecked cast from a value to a parsed map value. In // debug builds a best effort is made to crash. If `IsParsedMap()` would // return false, calling this method is undefined behavior. - const ParsedMapValue& GetParsedMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const ParsedMapValue& GetParsedMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetParsedMap(); + } const ParsedMapValue& GetParsedMap() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ParsedMapValue GetParsedMap() &&; ParsedMapValue GetParsedMap() const&&; @@ -1679,7 +1729,9 @@ class Value final { // debug builds a best effort is made to crash. If `IsParsedMapField()` would // return false, calling this method is undefined behavior. const ParsedMapFieldValue& GetParsedMapField() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetParsedMapField(); + } const ParsedMapFieldValue& GetParsedMapField() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ParsedMapFieldValue GetParsedMapField() &&; @@ -1688,7 +1740,9 @@ class Value final { // Performs an unchecked cast from a value to a parsed message value. In // debug builds a best effort is made to crash. If `IsParsedMessage()` would // return false, calling this method is undefined behavior. - const ParsedMessageValue& GetParsedMessage() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const ParsedMessageValue& GetParsedMessage() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetParsedMessage(); + } const ParsedMessageValue& GetParsedMessage() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ParsedMessageValue GetParsedMessage() &&; @@ -1699,7 +1753,9 @@ class Value final { // `IsParsedRepeatedField()` would return false, calling this method is // undefined behavior. const ParsedRepeatedFieldValue& GetParsedRepeatedField() & - ABSL_ATTRIBUTE_LIFETIME_BOUND; + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetParsedRepeatedField(); + } const ParsedRepeatedFieldValue& GetParsedRepeatedField() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ParsedRepeatedFieldValue GetParsedRepeatedField() &&; @@ -1708,7 +1764,9 @@ class Value final { // Performs an unchecked cast from a value to a parsed struct value. In // debug builds a best effort is made to crash. If `IsParsedStruct()` would // return false, calling this method is undefined behavior. - const ParsedStructValue& GetParsedStruct() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const ParsedStructValue& GetParsedStruct() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetParsedStruct(); + } const ParsedStructValue& GetParsedStruct() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; ParsedStructValue GetParsedStruct() &&; @@ -1717,7 +1775,9 @@ class Value final { // Performs an unchecked cast from a value to a string value. In // debug builds a best effort is made to crash. If `IsString()` would return // false, calling this method is undefined behavior. - const StringValue& GetString() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const StringValue& GetString() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetString(); + } const StringValue& GetString() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; StringValue GetString() &&; StringValue GetString() const&&; @@ -1725,7 +1785,7 @@ class Value final { // Performs an unchecked cast from a value to a struct value. In // debug builds a best effort is made to crash. If `IsStruct()` would return // false, calling this method is undefined behavior. - StructValue GetStruct() &; + StructValue GetStruct() & { return std::as_const(*this).GetStruct(); } StructValue GetStruct() const&; StructValue GetStruct() &&; StructValue GetStruct() const&&; @@ -1738,7 +1798,9 @@ class Value final { // Performs an unchecked cast from a value to a type value. In // debug builds a best effort is made to crash. If `IsType()` would return // false, calling this method is undefined behavior. - const TypeValue& GetType() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const TypeValue& GetType() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetType(); + } const TypeValue& GetType() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; TypeValue GetType() &&; TypeValue GetType() const&&; @@ -1751,7 +1813,9 @@ class Value final { // Performs an unchecked cast from a value to an unknown value. In // debug builds a best effort is made to crash. If `IsUnknown()` would return // false, calling this method is undefined behavior. - const UnknownValue& GetUnknown() & ABSL_ATTRIBUTE_LIFETIME_BOUND; + const UnknownValue& GetUnknown() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetUnknown(); + } const UnknownValue& GetUnknown() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; UnknownValue GetUnknown() &&; UnknownValue GetUnknown() const&&;