node_iterator3.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_iterator3.hpp"
  5. #include <string>
  6. #include <memory>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <boost/mem_fn.hpp>
  10. #include <cassert>
  11. int main()
  12. {
  13. #if defined(BOOST_NO_CXX11_SMART_PTR)
  14. std::auto_ptr<node<int> > nodes(new node<int>(42));
  15. #else
  16. std::unique_ptr<node<int> > nodes(new node<int>(42));
  17. #endif
  18. nodes->append(new node<std::string>(" is greater than "));
  19. nodes->append(new node<int>(13));
  20. // Check interoperability
  21. assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get()));
  22. assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get()));
  23. assert(node_iterator(nodes.get()) != node_const_iterator());
  24. assert(node_const_iterator(nodes.get()) != node_iterator());
  25. std::copy(
  26. node_iterator(nodes.get()), node_iterator()
  27. , std::ostream_iterator<node_base>(std::cout, " ")
  28. );
  29. std::cout << std::endl;
  30. std::for_each(
  31. node_iterator(nodes.get()), node_iterator()
  32. , boost::mem_fn(&node_base::double_me)
  33. );
  34. std::copy(
  35. node_const_iterator(nodes.get()), node_const_iterator()
  36. , std::ostream_iterator<node_base>(std::cout, "/")
  37. );
  38. std::cout << std::endl;
  39. return 0;
  40. }