doc_recursive.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. using namespace boost::intrusive;
  16. typedef list_base_hook<> BaseHook;
  17. //A recursive class
  18. class Recursive : public BaseHook
  19. {
  20. private:
  21. Recursive(const Recursive&);
  22. Recursive & operator=(const Recursive&);
  23. public:
  24. Recursive() : BaseHook(), children(){}
  25. list< Recursive, base_hook<BaseHook> > children;
  26. };
  27. int main()
  28. {
  29. Recursive f, f2;
  30. //A recursive list of Recursive
  31. list< Recursive, base_hook<BaseHook> > l;
  32. //Insert a node in parent list
  33. l.insert(l.begin(), f);
  34. //Insert a node in child list
  35. l.begin()->children.insert(l.begin()->children.begin(), f2);
  36. //Objects properly inserted
  37. assert(l.size() == l.begin()->children.size());
  38. assert(l.size() == 1);
  39. //Clear both lists
  40. l.begin()->children.clear();
  41. l.clear();
  42. return 0;
  43. }
  44. //]