Sign in to follow this  
Rickert

Boost.intrusive multiple containers

Recommended Posts

Hi everyone,

In the boost.intrusive document, it mentions about using multiple containers to store in one object. However, there's no actual example, so I made my own. Is this the right way to do?

[code]
#include <boost/intrusive/list.hpp>
struct tag1;
class A:public list_member_hook<>, public list_member_hook<tag<tag1> >
{
}

typedef list_base_hook<tag<tag1> > TagHook;
typedef list<A> DefaultList;
typedef list<A, base_hook<TagHook> > TagList;

int main()
{
DefaultList dList;
agList tList;
A *a = new A();
dList.push_back(a);
tList.push_back(a);
}
[/code]

If I add another container of the same type (such as adding another DefaultList), it will produce error. Is this intended? Why are we not allowed to use the second container of the same type?

Share this post


Link to post
Share on other sites
[quote name='Rickert' timestamp='1306750991' post='4817451']
If I add another container of the same type (such as adding another DefaultList), it will produce error. Is this intended? Why are we not allowed to use the second container of the same type?
[/quote]
You can't define two different containers as the same type because it's already defined as a specific type. Is that what you were asking?

Share this post


Link to post
Share on other sites
[quote name='way2lazy2care' timestamp='1306763647' post='4817502']
[quote name='Rickert' timestamp='1306750991' post='4817451']
If I add another container of the same type (such as adding another DefaultList), it will produce error. Is this intended? Why are we not allowed to use the second container of the same type?
[/quote]
You can't define two different containers as the same type because it's already defined as a specific type. Is that what you were asking?
[/quote]
For example, we can have:

[code]int a,b,c;[/code]

But why not:

[code]DefaultList a,b,c;[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this