I am trying to parse a string of the form:
f 1 2 3 4 f 1 2 3 f 1 2 3 4 5
Using boost spirit, I have:
using boost::spirit::qi::uint_;
using boost::spirit::qi::double_;
using boost::spirit::qi::_1;
using boost::spirit::qi::phrase_parse;
using boost::spirit::ascii::space;
using boost::phoenix::ref;
using boost::phoenix::push_back;
std::vector<unsigned int> v;
r = phrase_parse(first_, last_,
// Begin grammar
(
'f' >> uint_[push_back(ref(v), _1)] >>*(uint_[push_back(ref(v), _1)])
)
,
// End grammar
space);// Begin grammar
However, I am getting a bunch of compile errors:
Error C2064 term does not evaluate to a function taking 2 arguments
Error C2668 'boost::phoenix::ref': ambiguous call to overloaded function
Error C2780 'bool boost::spirit::qi::phrase_parse(Iterator &,Iterator,Expr &,const Skipper &,boost::spirit::qi::skip_flag)': expects 5 arguments - 3 provided
Not really sure whats wrong because the form just follows the example program given in the boost spirit documentation.
Also, note that I am using boost 1_55 with MSVC 2015 ( can't really change these)
For a fixed number of integers after the 'f' the following compiles and works:
unsigned int v1 = 0, v2 = 0, v3 = 0;
r = phrase_parse(first_, last_,
// Begin grammar
(
'f' >> uint_[ref(v1) = _1]
>> uint_[ref(v2) = _1] >> uint_[ref(v3) = _1]
),
// End grammar
space);
Your code isn't self contained, but we can guess that
refis ambgious, sincestd::refwill be picked due tostd::vectorbeing declared in namespacestd: ADL.(That problem doesn't occur with the separate
v1,v2,v3since primitive types do not have an associated namespace).Therefore being less liberal (more hygienic) with the using declarations this compiles fine for me on Boost 1.55.0:
Live On Coliru(c++11)
Tested locally with Boost 1.55/Spirit v2.53:
Side Notes: UNCOMPLICATE
However, there's no need for any of the complexity.
any sequence
p >> *pis by definition equivalent to+ppush-back (back-insertion) is already the default action for container attributes, so why have semantic actions?
This has the exact same effect without the compilation overhead and code complexity. You'd never run into the ADL snag in the first place.
**Live On Coliru**¹
Printing the exact same output.
¹ note how the simplification also removed the dependance on now-deprecated Phoenix headers