Closed pulver closed 3 years ago
Issue resolved. A string
is a sequence/vector of characters, so when an optional operator -
is applied, it collapses to the sequence. In other words, remove the boost::optional
and test to see if it is empty to see if there was a match or not.
Issue resolved. A
string
is a sequence/vector of characters, so when an optional operator-
is applied, it collapses to the sequence. In other words, remove theboost::optional
and test to see if it is empty to see if there was a match or not.
Yes, but I still want to investigate if this is a bug or not. The optional and use of - seems like a valid use-case, at first glance.
It is definitely a bug.
I recently observed the root issue, but have not come to a solution. The issue is about handling container attributes in sequence && tuple attribute partitioning in sequence && passing thru unary a partitioned tuple attribute. In more details: tuple partitioning creates an iterator range of single element and it is not unwrapped because it will be passed to another sequence parser, and it is something that parse_into_container_impl
relies on currently.
MWE:
#include <boost/spirit/home/x3.hpp>
#include <boost/fusion/include/std_pair.hpp>
int main()
{
using boost::spirit::x3::char_;
using boost::spirit::x3::int_;
char const* const it = "123:abc";
std::pair<int, boost::optional<std::string>> v;
parse(it, it, int_ >> -(':' >> +char_), v);
}
In Boost 1.70.0, starting with
example/x3/employee.cpp
and applying the diff:results in compiler errors, including
In contrast, the following diff does successfully compile:
Summary
The
optional
operator unary minus (-
) works as expected when parsing a singledouble_
into aboost::optional<double>
member variable, but does not work as expected when parsing the compound parserquoted_string
into a correspondingboost::optional<std::string>
.