PageRenderTime 20ms CodeModel.GetById 10ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/iterator/example/node_iterator3.cpp

http://hadesmem.googlecode.com/
C++ | 43 lines | 32 code | 7 blank | 4 comment | 4 complexity | a19120bcd83e338a4d65bb0f92057232 MD5 | raw file
 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_iterator3.hpp"
 6#include <string>
 7#include <memory>
 8#include <iostream>
 9#include <algorithm>
10#include <boost/mem_fn.hpp>
11#include <cassert>
12
13int main()
14{
15    std::auto_ptr<node<int> > nodes(new node<int>(42));
16    nodes->append(new node<std::string>(" is greater than "));
17    nodes->append(new node<int>(13));
18
19    // Check interoperability
20    assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get()));
21    assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get()));
22    
23    assert(node_iterator(nodes.get()) != node_const_iterator());
24    assert(node_const_iterator(nodes.get()) != node_iterator());
25    
26    std::copy(
27        node_iterator(nodes.get()), node_iterator()
28      , std::ostream_iterator<node_base>(std::cout, " ")
29    );
30    std::cout << std::endl;
31    
32    std::for_each(
33        node_iterator(nodes.get()), node_iterator()
34      , boost::mem_fn(&node_base::double_me)
35    );
36
37    std::copy(
38        node_const_iterator(nodes.get()), node_const_iterator()
39      , std::ostream_iterator<node_base>(std::cout, "/")
40    );
41    std::cout << std::endl;
42    return 0;
43}