-
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
How to get a vector of values using a parser that operates on the fusion::view
?
#728
Comments
fusion::view
.fusion::view
?
It works good, when i need to get one element(not a vector): |
I don't think so. You need a mutable sequence. Views are not. Edit: Disregard. |
I see. So it's not really about mutability, but the requirement of std::vector to be able to default construct its elements. |
We just need to disable this requirement on the Spirit side. And i suppose, we can do it only for sequence of some views |
What does it mean for a rule to produce a view. Where that view will point to? |
I can't understand. You mean that this issue not possible?
I suppose that view won't have a long lifetime, it will be created just to be passed into child parse function as Attribute, and it will be point to element of user passed container from outside as Attribute. |
Again, the issue here is that |
fix for it looks like very easy |
But i don't tested: I may create a PR, if you are interesting. |
Interesting trick! |
Look at rules like they are functions witch returns values. What does it mean to return a view from a function? Assuming it is a stateless function -- It means it has received a view (a reference) as an argument. It is a an implementation detail that parsers receive a reference to the attribute, it could be done in another way, by returning values. Usually, Spirit parsers create a temporary to parse value to, and after parsing is done the value is is copied to the destination, parsing directly into the destination is just an optimization.
Multiple question surfaces from this:
See, I understand there might be uses for producing views from rules, but your question looks like xyproblem.
Or parsing into an optional. |
No, it's not a my intention. I answered this question not for reorder/slice fields, I do it for boostorg/fusion#241, and real examples will have |
Another words, answer for this question need for me to get rid of |
Sequence parser internally converts a tuple into a fusion view, it should not require anything from Spirit to enable that. I would expect that adding PRF support to Fusion means that |
Totally agree with you. But |
We have no choice when user need to parse into a container of We don't want short-lived attribute when user need to parse into one |
It was create inside an 'x3::parse' call and it will die here. There is no links to it outside the call |
You just going the wrong way. I see no point for rules to have a view attribute, it also does not make logical sense to me. The only reason you want them is to workaround something that you are not telling here (UPD: I think I have found which boostorg/fusion#241 (comment)). If you want to make Fusion interop with PRF -- you should make Fusion functions on views to work with that new Fusion view type. Spirit should work out-of-the box when you implement all necessary Fusion stuff (and if it does not - file an issue about that). |
After thinking about it, I think I am with @Kojoley here. Special case should be avoided as much as possible. There ought to be another solution that does not require special handling for a particular type/attribute without any workarounds? |
Example code
https://godbolt.org/z/W8vsTPM6f
Current behaviour
Won't compile because
fusion::reverse_view
has no default constructor.Expected behaviour
To print:
Hello. Is it possible to implement support for this functionality on the Boost Spirit side? Thanks.
The text was updated successfully, but these errors were encountered: