I want to parse into a std::unordered_map
.
Example Code:
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;
}
With the following main:
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;
}
and one example file:
1,2,3
2,3,4
3,4,5
The compiler error message is:
.... ‘class std::unordered_map<int, Base>’ has no member named ‘push_back’
What to do next, is there a way da adapt std::unordered_map
?
Likee jv_ supposed, updating my boost version fixed the problem.