-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
X3: plain into variant of single element tuple #716
Comments
Don't know variant or single element tuple or both, but not x3::symbols: #include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
namespace ast {
struct tagged_token { int token; };
}
BOOST_FUSION_ADAPT_STRUCT(ast::tagged_token, token)
int main() {
namespace x3 = boost::spirit::x3;
char const* iter = "/** /**/", * const end = iter + std::strlen(iter);
x3::variant<ast::tagged_token> x;
x3::parse(iter, end, x3::attr(int{}), x);
} |
It seems that not the single element variant is the problem. It depends on the number of struct/class members. No member works, two or more members works but not one member: #include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <variant>
struct no_member {};
struct one_member {
int a;
};
BOOST_FUSION_ADAPT_STRUCT(one_member, a)
struct two_members {
int a{};
int b{};
};
BOOST_FUSION_ADAPT_STRUCT(two_members, a, b)
int main()
{
namespace x3 = boost::spirit::x3;
char const* iter = "", * const end = iter + std::strlen(iter);
std::variant<no_member, one_member, two_members> x;
x3::parse(iter, end, x3::attr(no_member{}), x); // This line compiles
x3::parse(iter, end, x3::attr(one_member{}), x); // This line failes
x3::parse(iter, end, x3::attr(two_members{}), x); // This line compiles
} Is there a workaround available for this behaviour? |
Use boost::variant instead of std::variant. |
OOPS! Adding obvious change to is_variant.hpp not enough. With the obvious change, now getting, using std::variant:
|
However, changing obvious portion of variant_has_substitute.hpp to:
and #including <boost/fusion/container.hpp> before seems to solve problem. |
@cppljevans Thank you for your response. Replacing Sorry for confusing with the original post of @Bockeman. |
This code does not compile
It seems the only way to successfully compile is to wrap the token (
x3::symbols<>
) into a rule (either inline, or with a separate rule definition). Is this an X3 implementation problem, or is it beyond the anticipated capabilities of X3?The text was updated successfully, but these errors were encountered: