7 #include <hilti/rt/extension-points.h> 8 #include <hilti/rt/result.h> 9 #include <hilti/rt/util.h> 21 inline auto& value_or_exception(
const std::optional<T>& t,
const char*
location) {
25 throw AttributeNotSet(
"struct attribute not set", location);
29 namespace detail::adl {
32 constexpr std::false_type has__str__helper(
long);
35 constexpr
auto has__str__helper(
int) -> decltype(std::declval<T>().__str__(), std::true_type{});
38 using has__str__ = decltype(has__str__helper<T>(0));
40 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isStruct, T>::value>* =
nullptr>
41 inline std::string
to_string(
const T& x, adl::tag ) {
42 if constexpr ( has__str__<T>() ) {
43 if (
auto s = T(x).__str__() )
50 auto render_one = [&](
auto k,
auto v) {
59 x.__visit(render_one);
60 return fmt(
"[%s]", fields);
std::string to_string(T &&x)
Definition: extension-points.h:26
Definition: location.h:86
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:13