Brian Silverman | 5962333 | 2018-08-04 23:36:56 -0700 | [diff] [blame^] | 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 | |
| 5 | #include "node_iterator2.hpp" |
| 6 | #include <string> |
| 7 | #include <memory> |
| 8 | #include <iostream> |
| 9 | #include <algorithm> |
| 10 | #include <boost/mem_fn.hpp> |
| 11 | #include <cassert> |
| 12 | |
| 13 | int main() |
| 14 | { |
| 15 | |
| 16 | #if defined(BOOST_NO_CXX11_SMART_PTR) |
| 17 | |
| 18 | std::auto_ptr<node<int> > nodes(new node<int>(42)); |
| 19 | |
| 20 | #else |
| 21 | |
| 22 | std::unique_ptr<node<int> > nodes(new node<int>(42)); |
| 23 | |
| 24 | #endif |
| 25 | |
| 26 | nodes->append(new node<std::string>(" is greater than ")); |
| 27 | nodes->append(new node<int>(13)); |
| 28 | |
| 29 | // Check interoperability |
| 30 | assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get())); |
| 31 | assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get())); |
| 32 | |
| 33 | assert(node_iterator(nodes.get()) != node_const_iterator()); |
| 34 | assert(node_const_iterator(nodes.get()) != node_iterator()); |
| 35 | |
| 36 | std::copy( |
| 37 | node_iterator(nodes.get()), node_iterator() |
| 38 | , std::ostream_iterator<node_base>(std::cout, " ") |
| 39 | ); |
| 40 | std::cout << std::endl; |
| 41 | |
| 42 | std::for_each( |
| 43 | node_iterator(nodes.get()), node_iterator() |
| 44 | , boost::mem_fn(&node_base::double_me) |
| 45 | ); |
| 46 | |
| 47 | std::copy( |
| 48 | node_const_iterator(nodes.get()), node_const_iterator() |
| 49 | , std::ostream_iterator<node_base>(std::cout, "/") |
| 50 | ); |
| 51 | std::cout << std::endl; |
| 52 | return 0; |
| 53 | } |