intrusive/example/doc_recursive.cpp
Ion Gaztañaga fbd8e26461 * Big refactoring in order to reduce template and debug symbol bloat.
* Fixes #8698
* Implemented SCARY iterators

[SVN r85165]
2013-07-28 22:10:37 +00:00

54 lines
1.3 KiB
C++

/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2013
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////
//[doc_recursive
#include <boost/intrusive/list.hpp>
#include <cassert>
using namespace boost::intrusive;
typedef list_base_hook<> BaseHook;
//A recursive class
class Recursive : public BaseHook
{
private:
Recursive(const Recursive&);
Recursive & operator=(const Recursive&);
public:
Recursive() : BaseHook(), children(){}
list< Recursive, base_hook<BaseHook> > children;
};
int main()
{
Recursive f, f2;
//A recursive list of Recursive
list< Recursive, base_hook<BaseHook> > l;
//Insert a node in parent list
l.insert(l.begin(), f);
//Insert a node in child list
l.begin()->children.insert(l.begin()->children.begin(), f2);
//Objects properly inserted
assert(l.size() == l.begin()->children.size());
assert(l.size() == 1);
//Clear both lists
l.begin()->children.clear();
l.clear();
return 0;
}
//]