doc_recursive_containers.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2009-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #include <boost/container/detail/config_begin.hpp>
  11. #include <boost/container/detail/workaround.hpp>
  12. //[doc_recursive_containers
  13. #include <boost/container/vector.hpp>
  14. #include <boost/container/stable_vector.hpp>
  15. #include <boost/container/deque.hpp>
  16. #include <boost/container/list.hpp>
  17. #include <boost/container/map.hpp>
  18. #include <boost/container/string.hpp>
  19. using namespace boost::container;
  20. struct data
  21. {
  22. int i_;
  23. //A vector holding still undefined class 'data'
  24. vector<data> v_;
  25. vector<data>::iterator vi_;
  26. //A stable_vector holding still undefined class 'data'
  27. stable_vector<data> sv_;
  28. stable_vector<data>::iterator svi_;
  29. //A stable_vector holding still undefined class 'data'
  30. deque<data> d_;
  31. deque<data>::iterator di_;
  32. //A list holding still undefined 'data'
  33. list<data> l_;
  34. list<data>::iterator li_;
  35. //A map holding still undefined 'data'
  36. map<data, data> m_;
  37. map<data, data>::iterator mi_;
  38. friend bool operator <(const data &l, const data &r)
  39. { return l.i_ < r.i_; }
  40. };
  41. struct tree_node
  42. {
  43. string name;
  44. string value;
  45. //children nodes of this node
  46. list<tree_node> children_;
  47. list<tree_node>::iterator selected_child_;
  48. };
  49. int main()
  50. {
  51. //a container holding a recursive data type
  52. stable_vector<data> sv;
  53. sv.resize(100);
  54. //Let's build a tree based in
  55. //a recursive data type
  56. tree_node root;
  57. root.name = "root";
  58. root.value = "root_value";
  59. root.children_.resize(7);
  60. root.selected_child_ = root.children_.begin();
  61. return 0;
  62. }
  63. //]
  64. #include <boost/container/detail/config_end.hpp>