Boost logo

Boost Users :

Subject: Re: [Boost-users] Recursive variant problem
From: Timothy Madden (terminatorul_at_[hidden])
Date: 2010-07-08 11:26:20


Larry Evans wrote:
> On 07/08/10 02:11, Timothy Madden wrote:
> > Larry Evans wrote:
> [snip]
> >> Maybe you could just use pointers to the enclosing composite, like in:
> >>
> >> #include <tr1/tuple>
> >> #include <vector>
> >>
> >> struct tuple_tree
> >> : std::tr1::tuple
> >> < float
> >> , int
> >> , std::vector<tuple_tree*>
> >> >
> >> {
> >> };
> >
> > I can use vector<tuple_tree> directly, with no pointer needed, and it
> > works,
>
> Hmm... I'm surprised. I would have thought a pointer would be
> needed to break the recursion because, otherwise, the tuple_tree CTOR
> would create an infinite tree. But now that I think more about it,
> the pointer is within the std::vector. No infinite tree is created
> because the vector is initially empty.

Well, as you can see, some people say you were correct, after all,
because C++ might place a requirement to always use complete types for
containers.

>
> > but I would expect boost::make_recursive_variant<> to do the
> > substitution correctly so I could create the type in-place.
> >
> > This structure is part of a bigger tuple of containers in my code, and
> > using tuple_tree would require me to declare it in advance, separately,
> > while make_recursive_variant would create the needed type in-place.
> >
> > Here is my code:
[...]
> > std::vector
> > <
> > boost::tuple
> > <
> > std::basic_string<TCHAR>, // uuid
> > int, // revision
> > std::basic_string<TCHAR>, // name
> > std::basic_string<TCHAR>, // desc
> > std::basic_string<TCHAR>, // status
> > std::basic_string<TCHAR>, // statusName,
> > std::basic_string<TCHAR>, // memo
> > std::basic_string<TCHAR>, // designFileName
> > std::vector
> > <
> > UIOVarEntry
>
>
> What happens if you just use this, IOW, just
> std::vector<UIOVarEntry>. There'd be no infinite tree created
> for the reasons cited earlier. Wouldn't this satisfy your
> requirements?
[...]

It bothers me that to compose my large structure I need some previously
declared class UIOVarEntry, to hold a certain number of components from
my big typedef. With make_recursive_variant I could have all my
structure declared in-place at once.

Thank you,
Timothy Madden


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