9 #include <hilti/rt/exception.h> 10 #include <hilti/rt/logging.h> 11 #include <hilti/rt/type-info.h> 23 bool has_label(
const T& t,
const TypeInfo* ti) {
24 if ( ti->tag != TypeInfo::Enum )
27 const auto& labels = ti->enum_->labels();
28 return std::any_of(labels.begin(), labels.end(),
29 [&](
const auto& l) {
return l.value != -1 && t.value() == l.value; });
42 T from_int(int64_t n) {
43 using Value =
typename T::Value;
44 static_assert(std::is_enum_v<Value>);
45 static_assert(std::is_same_v<std::underlying_type_t<Value>, int64_t>);
46 return static_cast<T
>(n);
62 T from_uint(uint64_t n) {
63 using Value =
typename T::Value;
64 static_assert(std::is_enum_v<Value>);
65 static_assert(std::is_same_v<std::underlying_type_t<Value>, int64_t>);
67 if ( n > static_cast<uint64_t>(std::numeric_limits<int64_t>::max()) )
68 throw InvalidValue(
"enum value exceeds range");
70 return static_cast<T
>(n);
void internalError(const std::string &msg) __attribute__((noreturn))
Definition: logging.cc:16