Skip to content

Commit 3c0ca95

Browse files
jckingcopybara-github
authored andcommitted
Finalize TypeValue
PiperOrigin-RevId: 733304874
1 parent 5549f42 commit 3c0ca95

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

common/legacy_value.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ absl::Status ModernValue(google::protobuf::Arena* arena,
10111011
if (type_name.empty()) {
10121012
return absl::InvalidArgumentError("empty type name in CelValue");
10131013
}
1014-
result = TypeValue{common_internal::LegacyRuntimeType(type_name)};
1014+
result = TypeValue(common_internal::LegacyRuntimeType(type_name));
10151015
return absl::OkStatus();
10161016
}
10171017
case CelValue::Type::kError:
@@ -1215,7 +1215,7 @@ google::api::expr::runtime::CelValue ModernValueToLegacyValueOrDie(
12151215

12161216
TypeValue CreateTypeValueFromView(google::protobuf::Arena* arena,
12171217
absl::string_view input) {
1218-
return common_internal::LegacyRuntimeType(input);
1218+
return TypeValue(common_internal::LegacyRuntimeType(input));
12191219
}
12201220

12211221
} // namespace interop_internal

common/values/type_value.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
4646
public:
4747
static constexpr ValueKind kKind = ValueKind::kType;
4848

49-
// NOLINTNEXTLINE(google-explicit-constructor)
50-
TypeValue(Type value) noexcept : value_(std::move(value)) {}
49+
explicit TypeValue(Type value) : value_(std::move(value)) {}
5150

5251
TypeValue() = default;
5352
TypeValue(const TypeValue&) = default;
@@ -82,16 +81,24 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
8281

8382
bool IsZeroValue() const { return false; }
8483

84+
ABSL_DEPRECATED(("Use type()"))
8585
const Type& NativeValue() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
8686
return value_;
8787
}
8888

89+
const Type& type() const ABSL_ATTRIBUTE_LIFETIME_BOUND { return value_; }
90+
8991
void swap(TypeValue& other) noexcept {
9092
using std::swap;
9193
swap(value_, other.value_);
9294
}
9395

94-
absl::string_view name() const { return NativeValue().name(); }
96+
absl::string_view name() const { return type().name(); }
97+
98+
friend void swap(TypeValue& lhs, TypeValue& rhs) noexcept {
99+
using std::swap;
100+
swap(lhs.value_, rhs.value_);
101+
}
95102

96103
private:
97104
friend struct NativeTypeTraits<TypeValue>;
@@ -100,8 +107,6 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
100107
Type value_;
101108
};
102109

103-
inline void swap(TypeValue& lhs, TypeValue& rhs) noexcept { lhs.swap(rhs); }
104-
105110
inline std::ostream& operator<<(std::ostream& out, const TypeValue& value) {
106111
return out << value.DebugString();
107112
}

0 commit comments

Comments
 (0)