summaryrefslogtreecommitdiff
path: root/libs/intrusive/test/recursive_test.cpp
blob: c72316bd6376442097440c78a3b379f990943783 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga  2007-2010
//
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/slist.hpp>
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/unordered_set.hpp>
#include <boost/intrusive/avl_set.hpp>
#include <boost/intrusive/sg_set.hpp>
#include <boost/intrusive/splay_set.hpp>
#include <boost/intrusive/treap_set.hpp>
#include <cassert>

using namespace boost::intrusive;

typedef list_base_hook<>            ListBaseHook;
typedef slist_base_hook<>           SListBaseHook;
typedef set_base_hook<>             SetBaseHook;
typedef unordered_set_base_hook<>   USetBaseHook;

class Foo;
typedef unordered_set<Foo, base_hook<USetBaseHook> > USet;

class Foo : public ListBaseHook, public SListBaseHook, public SetBaseHook, public USetBaseHook
{
   USet::bucket_type buckets[1];
   Foo(const Foo &);
   Foo & operator=(const Foo &);

   public:
   Foo() : uset_children(USet::bucket_traits(buckets, 1))
   {}
   list <Foo, base_hook<ListBaseHook> >  list_children;
   slist<Foo, base_hook<SListBaseHook> > slist_children;
   set  <Foo, base_hook<SetBaseHook> >   set_children;
   USet  uset_children;
};

void instantiate()
{
   list< Foo, base_hook<ListBaseHook> >   list_;   list_.clear();
   slist< Foo, base_hook<SListBaseHook> > slist_;  slist_.clear();
   set< Foo, base_hook<SetBaseHook> > set_;  set_.clear();
   
   USet::bucket_type buckets[1];
   USet unordered_set_(USet::bucket_traits(buckets, 1));  unordered_set_.clear();
}
int main()
{
   instantiate();

   //A small test with list
   {
      Foo f, f2;
      list< Foo, base_hook<ListBaseHook> > l;
      l.insert(l.begin(), f);
      l.begin()->list_children.insert(l.begin()->list_children.begin(), f2);
      assert(l.size() == l.begin()->list_children.size());
      l.begin()->list_children.clear();
      l.clear();
   }
   return 0;
}