• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga  2006-2013
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 //    (See accompanying file LICENSE_1_0.txt or copy at
7 //          http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
10 //
11 /////////////////////////////////////////////////////////////////////////////
12 //[doc_recursive
13 #include <boost/intrusive/list.hpp>
14 #include <cassert>
15 
16 using namespace boost::intrusive;
17 
18 typedef list_base_hook<> BaseHook;
19 
20 //A recursive class
21 class Recursive : public BaseHook
22 {
23    private:
24    Recursive(const Recursive&);
25    Recursive & operator=(const Recursive&);
26 
27    public:
Recursive()28    Recursive() : BaseHook(), children(){}
29    list< Recursive, base_hook<BaseHook> > children;
30 };
31 
main()32 int main()
33 {
34    Recursive f, f2;
35    //A recursive list of Recursive
36    list< Recursive, base_hook<BaseHook> > l;
37 
38    //Insert a node in parent list
39    l.insert(l.begin(), f);
40 
41    //Insert a node in child list
42    l.begin()->children.insert(l.begin()->children.begin(), f2);
43 
44    //Objects properly inserted
45    assert(l.size() == l.begin()->children.size());
46    assert(l.size() == 1);
47 
48    //Clear both lists
49    l.begin()->children.clear();
50    l.clear();
51    return 0;
52 }
53 //]
54