Re: x3::variant vs boost::variant

Joel de Guzman <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 1/30/16 5:24 PM, Baptiste Wicht wrote:
> Hi guys,
>
> I just tested compiling my X3 parser with Boost 1.59 and it worked like
> a charm :)
>
> Now, I'll start using my real AST instead of the nodes I've written to
> test X3.
>
> I'm having a problem at this point with variant types. My old AST use
> boost::variant and recursive_wrapper while my new AST use x3::variant
> and forward_ast.
>
> The new way (especially getting rid of recursive_wrapper) is nicer in my
> opinion, so I tried adapting my tree to use x3::variant and forward_ast,
> but it seems that a lot of code will need to be changed :( I found at
> least issues with operator<< (easily fixable). And apparently you cannot
> construct a x3::variant<x1,x2> from a x2. That seems really extreme
> since I'm doing that all over the place with boost::variant.
>
> It seems that X3 don't mind boost::variant and recursive_wrapper, so
> what would be the advantages of using x3::variant and forward_ast ?

There are performance advantages with x3::variant. Boost variant has this
odd (IMO) requirement that prevents it to move recursive variants
cheaply. There was an ensuing debate over that some years ago. It
boils down to the never-empty guarantee. The way around that is to
have some kind of nullable object that I use in x3 to make move a
cheap pointer swap.

Another advantage is that you have a unique type everytime. An xr variant
is a user struct/class that you can use for overloading and type detection.
A variant, OTOH is defined by its structure. Hence, for example, variant<float, int>
does not say about its type, but only its structure. If you have a typedef
my_type and his_type both having the same variant<float, int>, they are not
unique types.

Patches/PRs very welcome of course.

Regards,
-- 
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.