Boost logo

Boost Users :

Subject: Re: [Boost-users] [variant] a question about recursive typedef
From: 龚逸玲 (gongyiling2010_at_[hidden])
Date: 2011-11-08 04:24:28


That cool! Thank you!

-----原始邮件-----
From: Nathan Ridge
Sent: Tuesday, November 08, 2011 10:42 AM Newsgroups:
gmane.comp.lib.boost.user
To: Boost Mailing List
Subject: Re: [variant] a question about recursive typedef

> Hello, everyone:
>
> I want write a general linked list(any element in the list may be
> a node or nested general linked list, so recursive).
> I think general linked list could by defined as following(see spirit's
> tutorial mini_xml):
>
> glist = *glist_node
> glist_node = node | glist
>
> so here is the typedef according to the above rules:
>
> struct node
> {
> int data;
> };
> typedef boost::variant<node, boost::recursive_wrapper<glist> > glist_node;
> //typedef 1
> typedef std::list<glist_node> glist; //typedef 2
>
> so the problem comes here, in the typedef 1, how can I forward declare
> glist?

I think this should work:

struct node
{
    int data;
};

typedef boost::make_recursive_variant<node,
std::list<boost::recursive_variant_> >::type glist_node;
typedef std::list<glist_node> glist;

Regards,
Nate

       =


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net