0

我想解析成一个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吗?

4

1 回答 1

1

Likee jv_ 应该,更新我的 boost 版本解决了这个问题。

于 2016-08-11T15:52:14.643 回答