template <typename Self>
struct evaluable : copyable<Self> {
std::string to_string() const;
using dispatch_table[[= v_table_data]] = anyxx::dispatch_table;
};
template <typename V>
requires std::formattable<V, char>
struct evaluable<V> {
static std::string to_string(V const& self) {
return std::format("{}", self);
}
};
using value = vany<evaluable, bool, int, double>;
using bool_int_double = vany_type_trait<value>::concrete_variant;
static_assert(std::is_same_v<bool_int_double, std::variant<bool, int, double>>);
template <typename Self>
struct node : anyxx::deleteable<Self> {
value evaluate() const;
using dispatch_table[[= v_table_data]] = anyxx::dispatch_table;
};
VANY_DISPACH_DECLARE(
, evaluate_plus,
(value(virtual_<any<evaluable>>, virtual_<any<evaluable>>)),
([]<no_any L, no_any R>(L&& l, R&& r) -> value
{ return std::forward<L>(l) + std::forward<R>(r);
}));
struct plus {
any<node> left_, right_;
value evaluate() const {
return evaluate_plus(left_.evaluate(), right_.evaluate());
}
};