2727#include " absl/status/status.h"
2828#include " absl/strings/cord.h"
2929#include " absl/strings/string_view.h"
30- #include " common/native_type.h"
3130#include " common/type.h"
3231#include " common/value_kind.h"
3332#include " common/values/values.h"
@@ -46,19 +45,17 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
4645 public:
4746 static constexpr ValueKind kKind = ValueKind::kType ;
4847
49- explicit TypeValue (Type value) {
50- ::new (static_cast <void *>(&value_[0 ])) Type (value);
51- }
48+ explicit TypeValue (Type value) : value_(value) {}
5249
5350 TypeValue () = default ;
5451 TypeValue (const TypeValue&) = default ;
5552 TypeValue (TypeValue&&) = default ;
5653 TypeValue& operator =(const TypeValue&) = default ;
5754 TypeValue& operator =(TypeValue&&) = default ;
5855
59- constexpr ValueKind kind () const { return kKind ; }
56+ static constexpr ValueKind kind () { return kKind ; }
6057
61- absl::string_view GetTypeName () const { return TypeType::kName ; }
58+ static absl::string_view GetTypeName () { return TypeType::kName ; }
6259
6360 std::string DebugString () const { return type ().DebugString (); }
6461
@@ -88,14 +85,7 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
8885 return type ();
8986 }
9087
91- const Type& type () const ABSL_ATTRIBUTE_LIFETIME_BOUND {
92- return *reinterpret_cast <const Type*>(&value_[0 ]);
93- }
94-
95- void swap (TypeValue& other) noexcept {
96- using std::swap;
97- swap (value_, other.value_ );
98- }
88+ const Type& type () const ABSL_ATTRIBUTE_LIFETIME_BOUND { return value_; }
9989
10090 absl::string_view name () const { return type ().name (); }
10191
@@ -105,24 +95,15 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
10595 }
10696
10797 private:
108- friend struct NativeTypeTraits <TypeValue>;
10998 friend class common_internal ::ValueMixin<TypeValue>;
11099
111- alignas ( Type) char value_[ sizeof (Type)] ;
100+ Type value_;
112101};
113102
114103inline std::ostream& operator <<(std::ostream& out, const TypeValue& value) {
115104 return out << value.DebugString ();
116105}
117106
118- template <>
119- struct NativeTypeTraits <TypeValue> final {
120- static bool SkipDestructor (const TypeValue& value) {
121- // Type is trivial.
122- return true ;
123- }
124- };
125-
126107} // namespace cel
127108
128109#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_TYPE_VALUE_H_
0 commit comments