Merge remote branch 'master'
[prop.git] / tests / listiter.pcc
blob3c0377846052f97d368ed346890ba796c91e58d6
1 //////////////////////////////////////////////////////////////////////////////
2 //  Testing the standard template library style iterator with lists.
3 //////////////////////////////////////////////////////////////////////////////
4 #include <prop/list.h>
5 #include <AD/stl/algorithm.h>
6 #include <AD/stl/streamiter.h>
7 #include <iostream.h>
9 datatype LIST<T> = #[] | #[ T ... LIST<T> ];
11 instantiate datatype LIST<int>, LIST<char *>;
13 int main()
15    LIST<char *> fruits = 
16       #[ "lemons", "apple", "oranges", "pears", "pineapple", "kiwi" ];
18    ostream_iterator<char *> p(cout, " ");
20    copy(list_iterator<LIST<char *>, char *>(fruits), 
21         list_iterator<LIST<char *>, char *>(list_nil(fruits)),
22         p);
23    cout << "\n";
25    LIST<int> primes = #[2, 3, 5, 7, 11, 13, 17, 19, 23];
26    
27    ostream_iterator<int> q(cout, " ");
28    copy(list_iterator<LIST<int>, int>(primes), 
29         list_iterator<LIST<int>, int>(list_nil(primes)),
30         q);
31    cout << "\n";
33    cout << "OK\n";