node_iterator1.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright David Abrahams 2004. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "node_iterator1.hpp"
  5. #include <string>
  6. #include <memory>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <functional>
  10. int main()
  11. {
  12. #if defined(BOOST_NO_CXX11_SMART_PTR)
  13. std::auto_ptr<node<int> > nodes(new node<int>(42));
  14. #else
  15. std::unique_ptr<node<int> > nodes(new node<int>(42));
  16. #endif
  17. nodes->append(new node<std::string>(" is greater than "));
  18. nodes->append(new node<int>(13));
  19. std::copy(
  20. node_iterator(nodes.get()), node_iterator()
  21. , std::ostream_iterator<node_base>(std::cout, " ")
  22. );
  23. std::cout << std::endl;
  24. std::for_each(
  25. node_iterator(nodes.get()), node_iterator()
  26. , std::mem_fun_ref(&node_base::double_me)
  27. );
  28. std::copy(
  29. node_iterator(nodes.get()), node_iterator()
  30. , std::ostream_iterator<node_base>(std::cout, "/")
  31. );
  32. std::cout << std::endl;
  33. }