blob: e673e78ec04c1ce17333fafb15f0c3537e06031a (
plain)
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
|
#include <iostream>
#include "vector.h"
struct Value
{
Value( const int data )
: data(data) {}
int data;
operator int() { return data; }
};
typedef Vector<Value> MyVect;
int main()
{
MyVect vector;
vector.append( Value(1) );
vector.append( Value(2) );
vector.append( Value(3) );
/* Move forward through the vector, get data directly. */
for ( MyVect::Iter i = vector; i.lte(); i++ )
std::cout << i->data << std::endl;
/* Move backwards through the vector, use conversion from (Value&) to int. */
for ( MyVect::Iter i = vector.last(); i.gtb(); i-- )
std::cout << *i << std::endl;
/* Find the value before value 3, iter is cast to (Value*). */
Value *last = vector.data + 2;
MyVect::Iter i = vector;
while ( i != last )
i.increment();
std::cout << *(--i) << std::endl;
return 0;
}
|