Test variadic template arguments.
[kdbg.git] / kdbg / testprogs / templates.cpp
blob3314f02896552f5b6170cc2d16408c0df92ad9ff
1 // This file test stack parsing capabilities of KDbg.
2 // Parsing function names can be quite tricky ;)
3 #include <iostream>
4 using namespace std;
6 struct S {
7 void operator>>(int)
9 cout << __PRETTY_FUNCTION__ << endl;
13 template<typename T>
14 struct templS {
15 void operator>(T)
17 cout << __PRETTY_FUNCTION__ << endl;
19 void operator<(T)
21 cout << __PRETTY_FUNCTION__ << endl;
26 namespace A {
27 namespace {
28 namespace B {
29 namespace {
30 namespace {
31 void g()
33 cout << __PRETTY_FUNCTION__ << endl;
35 } // namespace
36 void Banong() { g(); }
37 } // namespace
38 void g() { Banong(); }
39 } // namespace B
40 void Aanong() { B::g(); }
41 } // namespace
42 void g() { Aanong(); }
44 void operator<<(int, S)
46 cout << __PRETTY_FUNCTION__ << endl;
49 template<typename T>
50 void operator<(T, S)
52 cout << __PRETTY_FUNCTION__ << endl;
54 } // namespace A
56 void operator<<(struct S&, int)
58 cout << __PRETTY_FUNCTION__ << endl;
61 template<typename T, typename U>
62 void operator<<(T&, U)
64 cout << __PRETTY_FUNCTION__ << endl;
67 void operator<(struct S&, int)
69 cout << __PRETTY_FUNCTION__ << endl;
72 template<typename T, typename U>
73 void operator<(T&, U)
75 cout << __PRETTY_FUNCTION__ << endl;
78 void f(const char* s)
80 A::g();
81 cout << s << endl;
84 template<typename T>
85 void indirect(T f, const char* s)
87 f(s);
90 template<class... Args>
91 void varargs(const char* sep, Args&&... args)
93 long vals[] = { args... };
94 for (auto v: vals)
95 cout << v << sep;
96 cout << endl;
99 int main()
101 S s1, s2;
102 f("direct");
103 s1 << 1;
104 s1 << s2;
105 s1 < 1;
106 s1 < s2;
108 A::operator<<(1, s1);
109 A::operator<(1, s1);
111 // the next lines test a templated function that accepts
112 // as one of its parameters a templated function pointer
113 void (*op1)(S&, S*) = operator<<;
114 operator<<(op1, s2);
115 void (*op2)(S&, S*) = operator<;
116 operator<(op2, s2);
117 indirect(f, "indirect");
119 // pointer to member function
120 void (S::*pm1)(int) = &S::operator>>;
121 (s1.*pm1)(1);
122 void (templS<int>::*pm2)(int) = &templS<int>::operator>;
123 templS<int> tSi;
124 (tSi.*pm2)(1);
125 tSi.operator<(1);
127 varargs(" : ", 1, short(-2), 4U, '3');