Add int(),'float() and str()` implicit conversions ref #4477.

This commit is contained in:
Artem Pavlenko 2024-11-08 09:53:43 +00:00
parent bb3106d04f
commit 3422472c7d
2 changed files with 30 additions and 8 deletions

View file

@ -217,6 +217,9 @@ struct unary_function_types_ : x3::symbols<unary_function_impl>
("log", log_impl()) //
("abs", abs_impl()) //
("length", length_impl()) //
("int", int_impl()) //
("float", float_impl()) //
("str", str_impl()) //
;
}
} const unary_func_types;

View file

@ -89,6 +89,25 @@ struct length_impl
value_type operator()(value_type const& val) const { return val.to_unicode().length(); }
};
// str
struct str_impl
{
value_type operator()(value_type const& val) const { return val.to_unicode(); }
};
// int
struct int_impl
{
value_type operator()(value_type const& val) const { return val.to_int(); }
};
// float
struct float_impl
{
value_type operator()(value_type const& val) const { return val.to_double(); }
};
// min
inline value_type min_impl(value_type const& arg1, value_type const& arg2)
{