我想解析为std::unordered_map
。
示例代码:
struct Base
{
int item1;
int item2;
};
BOOST_FUSION_ADAPT_STRUCT(Base, item1, item2)
namespace grammar
{
using namespace boost::spirit::x3;
auto base_ = rule<struct base_, Base>{"base"}
= repeat(2)[ int_ ];
auto start = rule<struct start, std::unordered_map<std::int32_t, Base>>{"start"}
= (id_ >> base_) % eol;
}
以下主要内容:
namespace ios = boost::iostreams;
namespace fs = boost::filesystem;
namespace x3 = boost::spirit::x3;
int main()
{
std::unordered_map<std::int32_t, Base> bases;
ios::mapped_file mmf("example.dat");
auto beg = std::begin(mmf);
auto end = std::end(mmf);
auto ret = x3::phrase_parse(beg, end, grammar::start, x3::char_(','), bases);
if (ret && beg == end)
{
std::cout << "Parse ok\n";
}
mmf.close();
return 0;
}
和一个示例文件:
1,2,3
2,3,4
3,4,5
编译器错误消息是:
.... ‘class std::unordered_map<int, Base>’ has no member named ‘push_back’
接下来该做什么,是否有适应std::unordered_map
的方法?
答案 0 :(得分:1)
Likee jv_假设,更新我的升级版修复了问题。