Opened 6 years ago
Last modified 5 years ago
#12932 new Feature Requests
"Char >> (Literal | Sequence)" unpacking
Reported by: | Owned by: | Joel de Guzman | |
---|---|---|---|
Milestone: | To Be Determined | Component: | spirit |
Version: | Boost 1.63.0 | Severity: | Problem |
Keywords: | unpacking | Cc: |
Description
This is the simplest I was able to reduce this to. What is going on here?
Requirements: -Boost 1.62 or 1.63 /w spirit v2 -C++03/C++11/C++14
Steps: g++ test.cpp && ./a.out
Expected: Success: "x" "a" "b" "c"
Result: Success: "x" "a" "" ""
#include <boost/spirit/include/qi.hpp> #include <cstdlib> #include <iostream> #include <string> int main(int argc, char * argv[]) { namespace qi = boost::spirit::qi; const std::string input("xabc"); char x = 0; char a = 0; char b = 0; char c = 0; const int result = qi::parse( input.begin(), input.end(), qi::char_ >> (qi::lit("Z") | (qi::char_ >> qi::char_ >> qi::char_)), x, a, b, c ); std::cout << (result ? "Success" : "Failure") << ": " << '"' << x << "\" \"" << a << "\" \"" << b << "\" \"" << c << '"' << std::endl; return result ? EXIT_SUCCESS : EXIT_FAILURE; }
Change History (3)
comment:1 by , 6 years ago
comment:2 by , 5 years ago
The attribute of the parser (qi::char_ >> qi::char_ >> qi::char_)
is boost::fusion::vector3<char, char, char>
so you should write your code this way :
#include <boost/spirit/include/qi.hpp> #include <cstdlib> #include <iostream> #include <string> int main(int argc, char * argv[]) { namespace qi = boost::spirit::qi; namespace fusion = boost::fusion; const std::string input("xabc"); char x = 0; fusion::vector3<char, char, char> v; const int result = qi::parse( input.begin(), input.end(), qi::char_ >> (qi::lit("Z") | (qi::char_ >> qi::char_ >> qi::char_)), x, v ); std::cout << (result ? "Success" : "Failure") << ": " << '"' << x << "\" \"" << fusion::at_c<0>(v) << "\" \"" << fusion::at_c<1>(v) << "\" \"" << fusion::at_c<2>(v) << '"' << std::endl; return result ? EXIT_SUCCESS : EXIT_FAILURE; }
comment:3 by , 5 years ago
Keywords: | unpacking added; or sequence removed |
---|---|
Summary: | Boost Spirit 1.63 "Char >> (Literal | Sequence)" Bug → "Char >> (Literal | Sequence)" unpacking |
Type: | Bugs → Feature Requests |
Amine is right here, though it is actually optional<vector3<char, char, char>>
. I consider this not a bug, but feature request.
Note:
See TracTickets
for help on using tickets.
Similarly, substituting this rule seems to generate the same result:
Am I missing something trivial here?