Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions common/values/type_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "absl/status/status.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
#include "common/native_type.h"
#include "common/type.h"
#include "common/value_kind.h"
#include "common/values/values.h"
Expand All @@ -46,19 +45,17 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
public:
static constexpr ValueKind kKind = ValueKind::kType;

explicit TypeValue(Type value) {
::new (static_cast<void*>(&value_[0])) Type(value);
}
explicit TypeValue(Type value) : value_(value) {}

TypeValue() = default;
TypeValue(const TypeValue&) = default;
TypeValue(TypeValue&&) = default;
TypeValue& operator=(const TypeValue&) = default;
TypeValue& operator=(TypeValue&&) = default;

constexpr ValueKind kind() const { return kKind; }
static constexpr ValueKind kind() { return kKind; }

absl::string_view GetTypeName() const { return TypeType::kName; }
static absl::string_view GetTypeName() { return TypeType::kName; }

std::string DebugString() const { return type().DebugString(); }

Expand Down Expand Up @@ -88,14 +85,7 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
return type();
}

const Type& type() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
return *reinterpret_cast<const Type*>(&value_[0]);
}

void swap(TypeValue& other) noexcept {
using std::swap;
swap(value_, other.value_);
}
const Type& type() const ABSL_ATTRIBUTE_LIFETIME_BOUND { return value_; }

absl::string_view name() const { return type().name(); }

Expand All @@ -105,24 +95,15 @@ class TypeValue final : private common_internal::ValueMixin<TypeValue> {
}

private:
friend struct NativeTypeTraits<TypeValue>;
friend class common_internal::ValueMixin<TypeValue>;

alignas(Type) char value_[sizeof(Type)];
Type value_;
};

inline std::ostream& operator<<(std::ostream& out, const TypeValue& value) {
return out << value.DebugString();
}

template <>
struct NativeTypeTraits<TypeValue> final {
static bool SkipDestructor(const TypeValue& value) {
// Type is trivial.
return true;
}
};

} // namespace cel

#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_TYPE_VALUE_H_