aboutsummaryrefslogtreecommitdiff
path: root/src/tests/list.cpp
blob: c45921e4b27004ffdcb477c83b142dd9453e59e8 (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
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
/*
 * Copyright (C) 2007 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/list.h"
#include <list>

typedef struct Bob
{
	int nID;
} Bob;

int main()
{
	Bu::List<int> l;

	l.append( 0 );

	for( int j = 3; j <= 21; j += 3 )
	{
		l.append( j );
		l.prepend( -j );
	}

	{
		Bu::List<int>::iterator i = l.begin();
		Bu::List<int>::iterator j = i;
		int a, b;
		a = *j;
		printf("end:  %s\n", (j != l.end())?"no":"yes");
		j--;
		printf("end:  %s\n", (j != l.end())?"no":"yes");
		j++;
		printf("end:  %s\n", (j != l.end())?"no":"yes");
		i = j;
		b = *i;
		printf("%d -> %d\n", a, b );
	}

	for( Bu::List<int>::iterator i = l.begin(); i != l.end(); i++ )
	{
		printf("%d ", *i );
	}
	printf("\n");
	for( Bu::List<int>::iterator i = l.begin(); i != l.end(); i++ )
	{
		Bu::List<int>::iterator j = i; j--;
		l.erase( i );
		i = j;
		if( i != l.end() )
			printf("!%d ", *i );
	}

	printf("\n\n");

	Bu::List<Bob> lb;
	for( int j = 0; j < 10; j++ )
	{
		Bob b;
		b.nID = j;
		lb.append( b );
	}

	const Bu::List<Bob> rb = lb;

	for( Bu::List<Bob>::const_iterator i = rb.begin(); i != rb.end(); i++ )
	{
		//i->nID += 2;
		//(*i).nID = 4;
		printf("%d ", i->nID );
	}
	printf("\n\n");
}