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 &&
static_cast<int64_t
>(t) == l.value; });
42 T from_int(int64_t n) {
43 static_assert(std::is_enum<T>::value && std::is_same_v<std::underlying_type_t<T>, int64_t>);
44 return static_cast<T
>(n);
60 T from_uint(uint64_t n) {
61 static_assert(std::is_enum<T>::value && std::is_same_v<std::underlying_type_t<T>, int64_t>);
63 if ( n > static_cast<uint64_t>(std::numeric_limits<int64_t>::max()) )
64 throw InvalidValue(
"enum value exceeds range");
66 return static_cast<T
>(n);
void internalError(const std::string &msg) __attribute__((noreturn))
Definition: logging.cc:17