gpt4 book ai didi

c++ - 提神气: change multiple target fields from semantic action

转载 作者:太空狗 更新时间:2023-10-29 21:16:13 26 4
gpt4 key购买 nike

我有以下输入 123, test, test456 我想运行一个 boost::qi 语法,以便输出是一个对 vector ,其中每个匹配都与某种类型相关联信息如:[(123, Int), (test, String), (test456, String)]

这是我到目前为止一直在尝试的:

enum class MatchType
{
Int,
String
}

在语法中

match = qi::alpha >> *(qi::alnum)[/*How to set the tuple to (matched value _1, string)*/]
| +qi::digit[ /*How to set the tuple to (matched value _1, Int)*/ ]

/* Tied but doesn't compile:
+qi::digit[
[]()
{
phoenix::at_c<0>(_val) = _1;
phoenix::at_c<1>(_val) = MatchType::Int;
}]
*/


qi::rule<Iterator, std::vector<std::pair<MatchType, std::string>>> match;

实现此目标的最佳方法是什么?

最佳答案

我只是建议

#include <boost/fusion/adapted/std_pair.hpp>

以后

my_pair = (qi::attr(MatchType::Int)    >> qi::int_)
| (qi::attr(MatchType::String) >> +qi::alnum);

关于c++ - 提神气: change multiple target fields from semantic action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35825138/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com