📄 templates.cc
字号:
{ return 0; }int operator<(const T2&, const T2&){ return 0; }int operator<(const T2&, char){ return 0; }int operator>=(const T2&, const T2&){ return 0; }int operator>=(const T2&, char){ return 0; }int operator>(const T2&, const T2&){ return 0; }int operator>(const T2&, char){ return 0; }T2 operator+(const T2 t, int i){ return t.integer + i; }T2 operator+(const T2 a, const T2& b){ return a.integer + b.integer; }T2& operator+=(T2& t, int i){ t.integer += i; return t; }T2& operator+=(T2& a, const T2& b){ a.integer += b.integer; return a; }T2 operator-(const T2 t, int i){ return t.integer - i; }T2 operator-(const T2 a, const T2& b){ return a.integer - b.integer; }T2& operator-=(T2& t, int i){ t.integer -= i; return t; }T2& operator-=(T2& a, const T2& b){ a.integer -= b.integer; return a; }T2 operator*(const T2 t, int i){ return t.integer * i; }T2 operator*(const T2 a, const T2& b){ return a.integer * b.integer; }T2& operator*=(T2& t, int i){ t.integer *= i; return t; }T2& operator*=(T2& a, const T2& b){ a.integer *= b.integer; return a; }T2 operator/(const T2 t, int i){ return t.integer / i; }T2 operator/(const T2 a, const T2& b){ return a.integer / b.integer; }T2& operator/=(T2& t, int i){ t.integer /= i; return t; }T2& operator/=(T2& a, const T2& b){ a.integer /= b.integer; return a; }T2 operator%(const T2 t, int i){ return t.integer % i; }T2 operator%(const T2 a, const T2& b){ return a.integer % b.integer; }T2& operator%=(T2& t, int i){ t.integer %= i; return t; }T2& operator%=(T2& a, const T2& b){ a.integer %= b.integer; return a; }template<class T>class T5 {public: T5(int); T5(const T5<T>&); ~T5(); static void* operator new(size_t) throw (); static void operator delete(void *pointer); int value(); static T X; T x; int val;};template<class T>T5<T>::T5(int v){ val = v; }template<class T>T5<T>::T5(const T5<T>&){}template<class T>T5<T>::~T5(){}template<class T>void*T5<T>::operator new(size_t) throw (){ return 0; }template<class T>voidT5<T>::operator delete(void *pointer){ }template<class T>intT5<T>::value(){ return val; }#if ! defined(__GNUC__) || defined(GCC_BUG)template<class T>T T5<T>::X;#endifT5<char> t5c(1);T5<int> t5i(2);T5<int (*)(char, void *)> t5fi1(3);T5<int (*)(int, double **, void *)> t5fi2(4); class x {public: int (*manage[5])(double, void *(*malloc)(unsigned size), void (*free)(void *pointer)); int (*device[5])(int open(const char *, unsigned mode, unsigned perms, int extra), int *(*read)(int fd, void *place, unsigned size), int *(*write)(int fd, void *place, unsigned size), void (*close)(int fd));};T5<x> t5x(5);#if !defined(__GNUC__) || (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)template class T5<char>;template class T5<int>;template class T5<int (*)(char, void *)>;template class T5<int (*)(int, double **, void *)>;template class T5<x>;#endifclass T7 {public: static int get(); static void put(int);};intT7::get(){ return 1; }voidT7::put(int i){ // nothing}// More template kinds. GDB 4.16 didn't handle these, but// Wildebeest does. Note: Assuming HP aCC is used to compile// this file; with g++ or HP cfront or other compilers the// demangling may not get done correctly.// Ordinary template, to be instantiated with different typestemplate<class T>class Foo {public: int x; T t; T foo (int, T);};template<class T> T Foo<T>::foo (int i, T tt){ return tt;}// Template with int parametertemplate<class T, int sz>class Bar {public: int x; T t; T bar (int, T);};template<class T, int sz> T Bar<T, sz>::bar (int i, T tt){ if (i < sz) return tt; else return 0;}// function template with int parametertemplate<class T> int dummy (T tt, int i){ return tt;}// Template with partial specializationstemplate<class T1, class T2>class Spec {public: int x; T1 spec (T2);};template<class T1, class T2>T1 Spec<T1, T2>::spec (T2 t2){ return 0;}template<class T>class Spec<T, T*> {public: int x; T spec (T*);};template<class T>T Spec<T, T*>::spec (T * tp){ return *tp;}// Template with char parametertemplate<class T, char sz>class Baz {public: int x; T t; T baz (int, T);};template<class T, char sz> T Baz<T, sz>::baz (int i, T tt){ if (i < sz) return tt; else return 0;}// Template with char * parametertemplate<class T, char * sz>class Qux {public: int x; T t; T qux (int, T);};template<class T, char * sz> T Qux<T, sz>::qux (int i, T tt){ if (sz[0] == 'q') return tt; else return 0;}// Template with a function pointer parametertemplate<class T, int (*f)(int) >class Qux1 {public: int x; T t; T qux (int, T);};template<class T, int (*f)(int)> T Qux1<T, f>::qux (int i, T tt){ if (f != 0) return tt; else return 0;}// Some functions to provide as arguments to templateint gf1 (int a) { return a * 2 + 13;}int gf2 (int a) { return a * 2 + 26;}char string[3];// Template for nested instantiationstemplate<class T>class Garply {public: int x; T t; T garply (int, T);};template<class T> T Garply<T>::garply (int i, T tt){ if (i > x) return tt; else { x += i; return tt; }}int main(){ int i;#ifdef usestubs set_debug_traps(); breakpoint();#endif i = i + 1; // New tests added here Foo<int> fint={0,0}; Foo<char> fchar={0,0}; Foo<volatile char *> fvpchar = {0, 0}; Bar<int, 33> bint; Bar<int, (4 > 3)> bint2; Baz<int, 's'> bazint; Baz<char, 'a'> bazint2; Qux<char, string> quxint2; Qux<int, string> quxint; Qux1<int, gf1> qux11; int x = fint.foo(33, 47); char c = fchar.foo(33, 'x'); volatile char * cp = fvpchar.foo(33, 0); int y = dummy<int> (400, 600); int z = bint.bar(55, 66); z += bint2.bar(55, 66); c = bazint2.baz(4, 'y'); c = quxint2.qux(4, 'z'); y = bazint.baz(4,3); y = quxint.qux(4, 22); y += qux11.qux(4, 22); y *= gf1(y) - gf2(y); Spec<int, char> sic; Spec<int, int *> siip; sic.spec ('c'); siip.spec (&x); Garply<int> f; Garply<char> fc; f.x = 13; Garply<Garply<char> > nf; nf.x = 31; x = f.garply (3, 4); fc = nf.garply (3, fc); y = x + fc.x; return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -