如何使用 Boost.Spirit.Qi 解析不同的结构?
在此示例中,员工结构是以“employee{int, string, string, double}”的形式解析。
我想知道是否可以修改此示例以解析不同类型的结构,例如“intern{int, string, string}”。
具体来说,我想将结构传递给在结构类型上重载的函数。如果我可以避免为此使用多态双重分派,而是保留被解析以静态匹配正确的重载函数的具体类型,那就太好了。
In this example, employee structs are parsed in the form "employee{int, string, string, double}".
I would like to know whether it is possible to modify this example to also parse different types of structs, like "intern{int, string, string}".
Specifically, I would like to then pass the structure to a function overloaded on the structure type. It would be great if I can avoid using polymorphic double dispatch for this, and instead preserve the concrete type that gets parsed to statically match the correct overloaded function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,这是可能的。为您想要解析的每种类型创建一个规则:
并将它们组合成一个替代方案:
这假设您有 2 个处理解析数据的函数:
这是您想要的吗?
Sure, that's possible. Create a rule for each of the types you want to parse:
and combine those into an alternative:
This assumes you have 2 functions handling the parsed data:
Is that what you want?