-
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: forward_ast - what is the correct usage #445
Comments
There also bunch of calc examples that use it.
IIUC
I do not understand what you meant, you did not provide a grammar (you shown only data structures), please provide an MWE. From the |
Here: https://sourceforge.net/p/spirit/mailman/message/34869892/ Quoting myself: There are performance advantages with x3::variant. Boost variant has this Another advantage is that you have a unique type everytime. An xr variant And indeed: "I just replaced all x3::variant/forward_ast by Nikita, feel free to add that comment in the docs or the code itself. |
After a bit of investigating I realized that
They just have to have proper grammars to prevent infinite left-recursion with no input consumption. My pitfall is that my code currently workarounds 3 different spirit bugs (especially "sequence in variant parser with container attribute" and type copying) and also has probably my own grammar bugs which results in much harder tracking when something goes wrong. Regarding 1-element sequences: I have already realized that Spirit prefers when the number of elements between |
Should xr be x3 instead? Seems likely since r is close to 3 on keyboard
I assume you mean boost::variant<float,int>. But I don't understand
Yes, yes! Please! Maybe even a doc similar to the one for valu_init.htm |
As you can see in the examples/use-cases, the x3 variant is meant to be subclassed. So you write something like: struct my_ast : x3::variant<...> ... { ... }; |
Is there a benchmark (I cannot find it in the linked thread)?
This is about copying/moving the non-recursive_wrapper objects (and not the case if the type has noexcept copy/move constructor https://www.boost.org/doc/libs/1_69_0/doc/html/variant/design.html#variant.design.never-empty.optimizations). The
I do not get the point, the same thing can be done with |
No there isn't a formal benchmark.
Yes you can. |
Should there be one?
What about the possible bug Nikita mentioned? |
What about it? There's a long underlying story behind this in the Boost list. Variant does not do a simple pointer stealing on move. I'm not sure if I have the time to dig it up. maybe search never-empty guarantee + variant + move. |
At least if both variants have the same recursive_wrapper type it will |
OK, I did some search. This is (I think) the discussion: and here: ">> A recursive_wrapper is not a pointer. It's a value-like wrapper
|
I think this is a better view of the complete thread: |
Hopefully, these threads will give a better idea of the necessity of x3::variant facility. |
Thanks, I will read the linked thread. |
What is not true?
I think you will get the same explanation as in the thread which already covers a lot of ground on the subject. |
This statement:
By nullifying you leaving an object in a valid state, as |
Ah and we're on the same boat :-) Alas, we lost in 2013 already. |
So the solution with x3 variant is to allow empty (relax the never empty guarantee). |
IIUC the bad thing could happen if variant use backup storage for doing this move, but it marked noexcept so no backup storage is used. Also there should be a test in variant for this case after doing that change all tests passed so... if there is no test case that broken and no one can show a counterexample I think that PR should be merged. |
I am reading the thread and see that the worrying is about |
That's the thing about the debate. It is not. There's no such thing as zombee/half-dead objects. "The moved-from state is part of the object's invariant, and objects in that state may become exposed in several ways (e.g. use std::remove on a sequence of them)" |
I did not say "zombee/half-dead objects", I was saying about the same thing as shown in an example given in standard [defns.valid]. If precondition not met - the call is illegal. |
There is pretty much nothing regarding
x3::forward_ast
in the documentation. The only example is rexpr, which uses it as one of the variant alternatives. I'm not sure if it's intended to be used anywhere else - I have a recursive grammar and I don't know whether something like this is valid:Currently I'm running into compilation errors which result from different types than expected:
forward_ast
intended to be used anywhere else than variant alternatives?child_blocks.get()
instead ofchild_blocks
)?The text was updated successfully, but these errors were encountered: