summaryrefslogtreecommitdiffstats
path: root/kdbg/testprogs/templates.cpp
blob: a667463a0f73fabd56514c023d9f949f5644ae4e (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// This file test stack parsing capabilities of KDbg.
// Parsing function names can be quite tricky ;)
#include <iostream>
using namespace std;

struct S {
	void operator>>(int)
	{
		cout << __PRETTY_FUNCTION__ << endl;
	}
};

template<typename T>
struct templS {
	void operator>(T)
	{
		cout << __PRETTY_FUNCTION__ << endl;
	}
	void operator<(T)
	{
		cout << __PRETTY_FUNCTION__ << endl;
	}
};


namespace A {
namespace {
namespace B {
namespace {
namespace {
void g()
{
	cout << __PRETTY_FUNCTION__ << endl;
}
} // namespace
void Banong() { g(); }
} // namespace
void g() { Banong(); }
} // namespace B
void Aanong() { B::g(); }
} // namespace
void g() { Aanong(); }

void operator<<(int, S)
{
	cout << __PRETTY_FUNCTION__ << endl;
}

template<typename T>
void operator<(T, S)
{
	cout << __PRETTY_FUNCTION__ << endl;
}
} // namespace A

void operator<<(struct S&, int)
{
	cout << __PRETTY_FUNCTION__ << endl;
}

template<typename T, typename U>
void operator<<(T&, U)
{
	cout << __PRETTY_FUNCTION__ << endl;
}

void operator<(struct S&, int)
{
	cout << __PRETTY_FUNCTION__ << endl;
}

template<typename T, typename U>
void operator<(T&, U)
{
	cout << __PRETTY_FUNCTION__ << endl;
}

void f(const char* s)
{
	A::g();
	cout << s << endl;
}

template<typename T>
void indirect(T f, const char* s)
{
	f(s);
}

int main()
{
	S s1, s2;
	f("direct");
	s1 << 1;
	s1 << s2;
	s1 < 1;
	s1 < s2;

	A::operator<<(1, s1);
	A::operator<(1, s1);

	// the next lines test a templated function that accepts
	// as one of its parameters a templated function pointer
	void (*op1)(S&, S*) = operator<<;
	operator<<(op1, s2);
	void (*op2)(S&, S*) = operator<;
	operator<(op2, s2);
	indirect(f, "indirect");

	// pointer to member function
	void (S::*pm1)(int) = &S::operator>>;
	(s1.*pm1)(1);
	void (templS<int>::*pm2)(int) = &templS<int>::operator>;
	templS<int> tSi;
	(tSi.*pm2)(1);
	tSi.operator<(1);
}