Boost logo

Boost :

Subject: Re: [boost] [intrusive] recursive intrusive data structures
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2010-08-09 12:20:27


On 14/06/2010 21:32, Ion Gaztañaga wrote:
> On 14/06/2010 19:08, Tim Blechmann wrote:
>> instantiating an intrusive list outside of the specific class, the gcc
>> complains:
>> error: ‘my_node<T>::children’ has incomplete type
>>
>> any idea?
>> thanks, tim
>
> It seems that default hook detection needs to instantiate the type
> early, I don't know why this is not needed for non template types, but I
> think that's not easy to workaround.

Sorry about the long delay, but I diddn't have time to look at this
until know.

I just realized that you can avoid any default hook (so the template
machinery does not need instantiate the (incomplete, because of
recursive definition) type "my_type" to discover hook attributes (the
hook might have different properties: pointer-type, auto_unlink, tag,
etc...). You can say it explicitly. Example:

#include <boost/intrusive/list.hpp>
#include <cassert>

using namespace boost::intrusive;

typedef list_base_hook<> BaseHook;
class Foo : public BaseHook
{
    public:
    list< Foo, base_hook<BaseHook> > children;
};

int main()
{
    Foo f, f2;
    list< Foo, base_hook<BaseHook> > l;
    l.insert(l.begin(), f);
    l.begin()->children.insert(l.begin()->children.begin(), f2);
    assert(l.size() == l.begin()->children.size());

    //Clear list in correct order to avoid any safe-hook assertion
    l.begin()->children.clear();
    l.clear();
    return 0;
}

Telling "list" the hook type avoids any early Foo instantiation. I will
see if other intrusive containers work the same way, put a test in the
library and add this note to the documentation.

I hope this helps,

Ion


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk