x3::variant vs boost::variant

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

x3::variant vs boost::variant

Baptiste Wicht
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 ?

Thanks

Baptiste

------------------------------------------------------------------------------
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=267308311&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

attachment0 (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Joel de Guzman
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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Baptiste Wicht
On Mon, Feb 08, 2016 at 07:53:14AM +0800, Joel de Guzman wrote:

> 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.
That is what I thought. Thanks for the answer.

> 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.

I've had some time to investigate the issue again:
* I had to use explicit construction in several places
* I had to add operators for x3 variants

The main problem that remains is with x3::variant and x3::forward_ast:

I have a type like this:

    using Type = boost::spirit::x3::variant<
            SimpleType,
            boost::spirit::x3::forward_ast<ArrayType>,
            boost::spirit::x3::forward_ast<TemplateType>,
            boost::spirit::x3::forward_ast<PointerType>
        >;

And a lot of code resembling this:

    if(auto* ptr = boost::get<ast::SimpleType>(&type)){
        //Do something on *ptr
    } else if(auto* ptr = boost::get<ast::ArrayType>(&type)){
        //Do something on *ptr
    } else if(auto* ptr = boost::get<ast::PointerType>(&type)){
        //...
    }
    //...

But this does not work since ArrayType is not a member of the variant
because of the forward_ast and I have an error from boost strict_get.

I really have a lot of code like this, I won't be able (neither have the
motivation for it) to change all of it. If there is no simple solution,
I'll use my old AST with boost::variant and recursive_wrapper.

Is there anything I can do to use boost::get with forward_ast ?

Thanks

Baptiste

------------------------------------------------------------------------------
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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

attachment0 (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Joel de Guzman
On 2/18/16 4:48 AM, Baptiste Wicht wrote:

> The main problem that remains is with x3::variant and x3::forward_ast:
>
> I have a type like this:
>
>      using Type = boost::spirit::x3::variant<
>              SimpleType,
>              boost::spirit::x3::forward_ast<ArrayType>,
>              boost::spirit::x3::forward_ast<TemplateType>,
>              boost::spirit::x3::forward_ast<PointerType>
>          >;
>
> And a lot of code resembling this:
>
>      if(auto* ptr = boost::get<ast::SimpleType>(&type)){
>          //Do something on *ptr
>      } else if(auto* ptr = boost::get<ast::ArrayType>(&type)){
>          //Do something on *ptr
>      } else if(auto* ptr = boost::get<ast::PointerType>(&type)){
>          //...
>      }
>      //...
>
> But this does not work since ArrayType is not a member of the variant
> because of the forward_ast and I have an error from boost strict_get.
>
> I really have a lot of code like this, I won't be able (neither have the
> motivation for it) to change all of it. If there is no simple solution,
> I'll use my old AST with boost::variant and recursive_wrapper.
>
> Is there anything I can do to use boost::get with forward_ast ?

There should be a solution. tell you what. Give me a minimal test
case and I can work on getting it compile and run as expected.

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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Baptiste Wicht
On Sat, Feb 20, 2016 at 05:42:14AM +0800, Joel de Guzman wrote:

> On 2/18/16 4:48 AM, Baptiste Wicht wrote:
>
> > The main problem that remains is with x3::variant and x3::forward_ast:
> >
> > I have a type like this:
> >
> >      using Type = boost::spirit::x3::variant<
> >              SimpleType,
> >              boost::spirit::x3::forward_ast<ArrayType>,
> >              boost::spirit::x3::forward_ast<TemplateType>,
> >              boost::spirit::x3::forward_ast<PointerType>
> >          >;
> >
> > And a lot of code resembling this:
> >
> >      if(auto* ptr = boost::get<ast::SimpleType>(&type)){
> >          //Do something on *ptr
> >      } else if(auto* ptr = boost::get<ast::ArrayType>(&type)){
> >          //Do something on *ptr
> >      } else if(auto* ptr = boost::get<ast::PointerType>(&type)){
> >          //...
> >      }
> >      //...
> >
> > But this does not work since ArrayType is not a member of the variant
> > because of the forward_ast and I have an error from boost strict_get.
> >
> > I really have a lot of code like this, I won't be able (neither have the
> > motivation for it) to change all of it. If there is no simple solution,
> > I'll use my old AST with boost::variant and recursive_wrapper.
> >
> > Is there anything I can do to use boost::get with forward_ast ?
>
> There should be a solution. tell you what. Give me a minimal test
> case and I can work on getting it compile and run as expected.
Here it is: http://coliru.stacked-crooked.com/a/641b689346ff322c

Thanks :)

> 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
> _______________________________________________
> Spirit-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/spirit-general

------------------------------------------------------------------------------
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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

attachment0 (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Joel de Guzman
On 2/20/16 5:14 PM, Baptiste Wicht wrote:

> On Sat, Feb 20, 2016 at 05:42:14AM +0800, Joel de Guzman wrote:
>> On 2/18/16 4:48 AM, Baptiste Wicht wrote:
>>
>>> The main problem that remains is with x3::variant and x3::forward_ast:
>>>
>>> I have a type like this:
>>>
>>>       using Type = boost::spirit::x3::variant<
>>>               SimpleType,
>>>               boost::spirit::x3::forward_ast<ArrayType>,
>>>               boost::spirit::x3::forward_ast<TemplateType>,
>>>               boost::spirit::x3::forward_ast<PointerType>
>>>           >;
>>>
>>> And a lot of code resembling this:
>>>
>>>       if(auto* ptr = boost::get<ast::SimpleType>(&type)){
>>>           //Do something on *ptr
>>>       } else if(auto* ptr = boost::get<ast::ArrayType>(&type)){
>>>           //Do something on *ptr
>>>       } else if(auto* ptr = boost::get<ast::PointerType>(&type)){
>>>           //...
>>>       }
>>>       //...
>>>
>>> But this does not work since ArrayType is not a member of the variant
>>> because of the forward_ast and I have an error from boost strict_get.
>>>
>>> I really have a lot of code like this, I won't be able (neither have the
>>> motivation for it) to change all of it. If there is no simple solution,
>>> I'll use my old AST with boost::variant and recursive_wrapper.
>>>
>>> Is there anything I can do to use boost::get with forward_ast ?
>>
>> There should be a solution. tell you what. Give me a minimal test
>> case and I can work on getting it compile and run as expected.
>
> Here it is: http://coliru.stacked-crooked.com/a/641b689346ff322c

There is a solution, but it involves some meta code that can slow down CT.
I'm not sure if it's worth it. The only reasonable solution is to simply
get<forward_ast<T>>(v).

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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Baptiste Wicht
On Sun, Feb 21, 2016 at 09:55:02AM +0800, Joel de Guzman wrote:

> On 2/20/16 5:14 PM, Baptiste Wicht wrote:
> > On Sat, Feb 20, 2016 at 05:42:14AM +0800, Joel de Guzman wrote:
> >> On 2/18/16 4:48 AM, Baptiste Wicht wrote:
> >>
> >>> The main problem that remains is with x3::variant and x3::forward_ast:
> >>>
> >>> I have a type like this:
> >>>
> >>>       using Type = boost::spirit::x3::variant<
> >>>               SimpleType,
> >>>               boost::spirit::x3::forward_ast<ArrayType>,
> >>>               boost::spirit::x3::forward_ast<TemplateType>,
> >>>               boost::spirit::x3::forward_ast<PointerType>
> >>>           >;
> >>>
> >>> And a lot of code resembling this:
> >>>
> >>>       if(auto* ptr = boost::get<ast::SimpleType>(&type)){
> >>>           //Do something on *ptr
> >>>       } else if(auto* ptr = boost::get<ast::ArrayType>(&type)){
> >>>           //Do something on *ptr
> >>>       } else if(auto* ptr = boost::get<ast::PointerType>(&type)){
> >>>           //...
> >>>       }
> >>>       //...
> >>>
> >>> But this does not work since ArrayType is not a member of the variant
> >>> because of the forward_ast and I have an error from boost strict_get.
> >>>
> >>> I really have a lot of code like this, I won't be able (neither have the
> >>> motivation for it) to change all of it. If there is no simple solution,
> >>> I'll use my old AST with boost::variant and recursive_wrapper.
> >>>
> >>> Is there anything I can do to use boost::get with forward_ast ?
> >>
> >> There should be a solution. tell you what. Give me a minimal test
> >> case and I can work on getting it compile and run as expected.
> >
> > Here it is: http://coliru.stacked-crooked.com/a/641b689346ff322c
>
> There is a solution, but it involves some meta code that can slow down CT.
> I'm not sure if it's worth it. The only reasonable solution is to simply
> get<forward_ast<T>>(v).
Too bad, tt makes for really inelegant code :(

I'll test the slowdown of my syntax with boost::variant instead of
x3::variant to see if it's still worth it.

------------------------------------------------------------------------------
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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

attachment0 (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Baptiste Wicht
In reply to this post by Joel de Guzman
On Sun, Feb 21, 2016 at 11:07:57AM +0100, Baptiste Wicht wrote:

> On Sun, Feb 21, 2016 at 09:55:02AM +0800, Joel de Guzman wrote:
> > On 2/20/16 5:14 PM, Baptiste Wicht wrote:
> > > On Sat, Feb 20, 2016 at 05:42:14AM +0800, Joel de Guzman wrote:
> > >> On 2/18/16 4:48 AM, Baptiste Wicht wrote:
> > >>
> > >>> The main problem that remains is with x3::variant and x3::forward_ast:
> > >>>
> > >>> I have a type like this:
> > >>>
> > >>>       using Type = boost::spirit::x3::variant<
> > >>>               SimpleType,
> > >>>               boost::spirit::x3::forward_ast<ArrayType>,
> > >>>               boost::spirit::x3::forward_ast<TemplateType>,
> > >>>               boost::spirit::x3::forward_ast<PointerType>
> > >>>           >;
> > >>>
> > >>> And a lot of code resembling this:
> > >>>
> > >>>       if(auto* ptr = boost::get<ast::SimpleType>(&type)){
> > >>>           //Do something on *ptr
> > >>>       } else if(auto* ptr = boost::get<ast::ArrayType>(&type)){
> > >>>           //Do something on *ptr
> > >>>       } else if(auto* ptr = boost::get<ast::PointerType>(&type)){
> > >>>           //...
> > >>>       }
> > >>>       //...
> > >>>
> > >>> But this does not work since ArrayType is not a member of the variant
> > >>> because of the forward_ast and I have an error from boost strict_get.
> > >>>
> > >>> I really have a lot of code like this, I won't be able (neither have the
> > >>> motivation for it) to change all of it. If there is no simple solution,
> > >>> I'll use my old AST with boost::variant and recursive_wrapper.
> > >>>
> > >>> Is there anything I can do to use boost::get with forward_ast ?
> > >>
> > >> There should be a solution. tell you what. Give me a minimal test
> > >> case and I can work on getting it compile and run as expected.
> > >
> > > Here it is: http://coliru.stacked-crooked.com/a/641b689346ff322c
> >
> > There is a solution, but it involves some meta code that can slow down CT.
> > I'm not sure if it's worth it. The only reasonable solution is to simply
> > get<forward_ast<T>>(v).
>
> Too bad, tt makes for really inelegant code :(
>
> I'll test the slowdown of my syntax with boost::variant instead of
> x3::variant to see if it's still worth it.
I just replaced all x3::variant/forward_ast by
boost::variant/recursive_wrapper and it is not good... The new parser is
70% slower than the x3::variant one :(

------------------------------------------------------------------------------
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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

attachment0 (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Baptiste Wicht
In reply to this post by Joel de Guzman
On Sun, Feb 21, 2016 at 09:55:02AM +0800, Joel de Guzman wrote:

> On 2/20/16 5:14 PM, Baptiste Wicht wrote:
> > On Sat, Feb 20, 2016 at 05:42:14AM +0800, Joel de Guzman wrote:
> >> On 2/18/16 4:48 AM, Baptiste Wicht wrote:
> >>
> >>> The main problem that remains is with x3::variant and x3::forward_ast:
> >>>
> >>> I have a type like this:
> >>>
> >>>       using Type = boost::spirit::x3::variant<
> >>>               SimpleType,
> >>>               boost::spirit::x3::forward_ast<ArrayType>,
> >>>               boost::spirit::x3::forward_ast<TemplateType>,
> >>>               boost::spirit::x3::forward_ast<PointerType>
> >>>           >;
> >>>
> >>> And a lot of code resembling this:
> >>>
> >>>       if(auto* ptr = boost::get<ast::SimpleType>(&type)){
> >>>           //Do something on *ptr
> >>>       } else if(auto* ptr = boost::get<ast::ArrayType>(&type)){
> >>>           //Do something on *ptr
> >>>       } else if(auto* ptr = boost::get<ast::PointerType>(&type)){
> >>>           //...
> >>>       }
> >>>       //...
> >>>
> >>> But this does not work since ArrayType is not a member of the variant
> >>> because of the forward_ast and I have an error from boost strict_get.
> >>>
> >>> I really have a lot of code like this, I won't be able (neither have the
> >>> motivation for it) to change all of it. If there is no simple solution,
> >>> I'll use my old AST with boost::variant and recursive_wrapper.
> >>>
> >>> Is there anything I can do to use boost::get with forward_ast ?
> >>
> >> There should be a solution. tell you what. Give me a minimal test
> >> case and I can work on getting it compile and run as expected.
> >
> > Here it is: http://coliru.stacked-crooked.com/a/641b689346ff322c
>
> There is a solution, but it involves some meta code that can slow down CT.
> I'm not sure if it's worth it. The only reasonable solution is to simply
> get<forward_ast<T>>(v).
I found a simple solution finally, I just created a wrapper around
boost::get and then used macros to generate partial specializations of
my wrapper for handling all forward_ast, this makes for nice code and
very few changes in the compiler (thank you sed). The wrapper and macro
is here: https://github.com/wichtounet/eddic/blob/develop/include/smart_get.hpp

------------------------------------------------------------------------------
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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

attachment0 (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: x3::variant vs boost::variant

Joel de Guzman
In reply to this post by Baptiste Wicht
On 2/21/16 7:19 PM, Baptiste Wicht wrote:

> On Sun, Feb 21, 2016 at 11:07:57AM +0100, Baptiste Wicht wrote:
>> On Sun, Feb 21, 2016 at 09:55:02AM +0800, Joel de Guzman wrote:
>>> On 2/20/16 5:14 PM, Baptiste Wicht wrote:
>>>> On Sat, Feb 20, 2016 at 05:42:14AM +0800, Joel de Guzman wrote:
>>>>> On 2/18/16 4:48 AM, Baptiste Wicht wrote:
>>>>>
>>>>>> The main problem that remains is with x3::variant and x3::forward_ast:
>>>>>>
>>>>>> I have a type like this:
>>>>>>
>>>>>>        using Type = boost::spirit::x3::variant<
>>>>>>                SimpleType,
>>>>>>                boost::spirit::x3::forward_ast<ArrayType>,
>>>>>>                boost::spirit::x3::forward_ast<TemplateType>,
>>>>>>                boost::spirit::x3::forward_ast<PointerType>
>>>>>>            >;
>>>>>>
>>>>>> And a lot of code resembling this:
>>>>>>
>>>>>>        if(auto* ptr = boost::get<ast::SimpleType>(&type)){
>>>>>>            //Do something on *ptr
>>>>>>        } else if(auto* ptr = boost::get<ast::ArrayType>(&type)){
>>>>>>            //Do something on *ptr
>>>>>>        } else if(auto* ptr = boost::get<ast::PointerType>(&type)){
>>>>>>            //...
>>>>>>        }
>>>>>>        //...
>>>>>>
>>>>>> But this does not work since ArrayType is not a member of the variant
>>>>>> because of the forward_ast and I have an error from boost strict_get.
>>>>>>
>>>>>> I really have a lot of code like this, I won't be able (neither have the
>>>>>> motivation for it) to change all of it. If there is no simple solution,
>>>>>> I'll use my old AST with boost::variant and recursive_wrapper.
>>>>>>
>>>>>> Is there anything I can do to use boost::get with forward_ast ?
>>>>>
>>>>> There should be a solution. tell you what. Give me a minimal test
>>>>> case and I can work on getting it compile and run as expected.
>>>>
>>>> Here it is: http://coliru.stacked-crooked.com/a/641b689346ff322c
>>>
>>> There is a solution, but it involves some meta code that can slow down CT.
>>> I'm not sure if it's worth it. The only reasonable solution is to simply
>>> get<forward_ast<T>>(v).
>>
>> Too bad, tt makes for really inelegant code :(
>>
>> I'll test the slowdown of my syntax with boost::variant instead of
>> x3::variant to see if it's still worth it.
>
> I just replaced all x3::variant/forward_ast by
> boost::variant/recursive_wrapper and it is not good... The new parser is
> 70% slower than the x3::variant one :(

X3 variant is quite fast, primarily because of the move issue with boost variant
recursive_wrapper. I complained about that, but lost the debate. That's why you
have  x3::variant/forward_ast now.

In the future, please consider using visitors instead of switch-by-type.

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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general