-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathiterator.node2.cpp
More file actions
39 lines (28 loc) · 972 Bytes
/
iterator.node2.cpp
File metadata and controls
39 lines (28 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "iterator.node2.hpp"
#include <string>
#include <memory>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <boost/mem_fn.hpp>
using namespace std;
ostream_iterator<node_base> out(cout, " ");
int main()
{
unique_ptr< node<int> > nodes(new node<int>(42));
nodes->append(new node<string>(" is greater than "));
nodes->append(new node<int>(13));
// Check interoperability
assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get()));
assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get()));
assert(node_iterator(nodes.get()) != node_const_iterator());
assert(node_const_iterator(nodes.get()) != node_iterator());
copy(node_iterator(nodes.get()), node_iterator(), out);
cout << endl;
for_each(node_iterator(nodes.get()), node_iterator(),
boost::mem_fn(&node_base::double_me)
);
copy(node_const_iterator(nodes.get()), node_const_iterator(), out);
cout << endl;
return 0;
}