Re: fusion pair issue?
Patrick Welche <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <20170331121154.GB943@quartz> |
Thank you so much for your answer! I was struck by this version: > See http://coliru.stacked-crooked.com/a/2a847ad1037640f3 No need to know the member names of a pair for a BOOST_FUSION wrapping. Given ciere.com/cppnow15/x3_docs/spirit/tutorials/rexpr.html: "We need to tell fusion about our rexpr struct to make it a first-class fusion citizen" I would never have guessed your solution was possible. Fusion is still necessary via #include <boost/fusion/include/std_pair.hpp> but nicely hidden. I have no idea what the correct fusion wrapping would be for a map (we had to know and list "first" and "second" for the pair), however thankfully I don't need to know! Thanks again, Patrick ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Spirit-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spirit-general
try.cpp
(text/plain, 779 B)
#define BOOST_SPIRIT_X3_DEBUG
#include <map>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/spirit/home/x3.hpp>
namespace x3 = boost::spirit::x3;
struct result
{
std::map<std::string, std::string> both;
};
int main()
{
std::string buf("one two;three four;");
std::string::const_iterator iter = buf.begin();
std::string::const_iterator end = buf.end();
result res;
bool ok = x3::parse(iter, end,
+( +x3::alnum >> ' ' >> +x3::alnum >> ';' ),
res.both);
if (!ok)
std::cout << "Parsing failed\n";
else if (iter != end)
std::cout << "Bit left over at the end: "
<< std::string(iter, end) << std::endl;
else
for (auto p : res.both) {
std::cout << "found: " << p.first << ' '
<< p.second << std::endl;
}
return 0;
}