Consider this code using Boost Spirit X3 (conceptually same goes for Boost Spirit Qi):
string command;
string value;
x3::parse(command.begin(), command.end(), "float:" >> x3::double_, value);
Why is this code not generating any error during compilation? Shouldn't "float:" >> x3::double_
parser have attribute of type double
and therefore not accept std::string
as 4th argument to parse
?
BTW, I know I could do this:
string value;
auto assign = [](auto& ctx){value = _attr(ctx)};
x3::parse(command.begin(), command.end(), "float:" >> x3::double_[assign], value)
which would generate an error, but it is more complicated than necessary.
As a last resort: any there any well-known replacements for sscanf
that would be type safe (possibly in boost)?