-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
92 lines (67 loc) · 1.24 KB
/
main.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include "ConsList.h"
#include <list>
using namespace std;
using namespace ImmutableCPP;
template<typename T>
void Print(ConsList<T> l)
{
for(; !l.empty() ; l = l.rest())
{
cout<<l.first().c_str()<<' ';
}
}
static size_t mynodes_constructed=0;
static size_t mynodes_destroyed=0;
class mynode
{public:
mynode():val(0){++mynodes_constructed;}
mynode(mynode const&o)
: val(o.val)
{
++mynodes_constructed;
}
mynode(size_t val)
: val(val)
{
++mynodes_constructed;
}
~mynode()
{
++mynodes_destroyed;
}
size_t val;
};
int main()
{
ConsList<string> justWorld;
{
ConsList<string> foo;
justWorld = foo = foo.cons("World");
foo = foo.cons("Hello");
cout<<"List: ";
Print(foo);
cout<<endl;
}
// Big list test
cout<<"Starting big cons"<<endl;
{
{
ConsList<mynode> big;
for(size_t i=0;i<(1000*1000*2);++i)
big = big.cons(i);
cout<<"Big cons done"<<endl;
}
cout<<"Big cons destroyed"<<endl;
}
{
{
std::list<mynode> big_stl;
for(size_t i=0;i<(1000*1000*2);++i)
big_stl.push_front(i);
cout<<"Big STL done"<<endl;
}
cout<<"Big STL destroyed"<<endl;
}
return 0;
}