Mercurial > emacs
annotate test/cedet/tests/testpolymorph.cpp @ 112278:ef719132ddfa
Nuke arch-tags.
| author | Glenn Morris <rgm@gnu.org> |
|---|---|
| date | Sat, 15 Jan 2011 15:16:57 -0800 |
| parents | 376148b31b5e |
| children |
| rev | line source |
|---|---|
| 105267 | 1 /** testpolymorph.cpp --- A sequence of polymorphism examples. |
| 2 * | |
|
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
107494
diff
changeset
|
3 * Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. |
| 105267 | 4 * |
| 5 * Author: Eric M. Ludlam <eric@siege-engine.com> | |
| 6 * | |
|
107494
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
7 * This file is part of GNU Emacs. |
| 105267 | 8 * |
|
107494
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
9 * GNU Emacs is free software: you can redistribute it and/or modify |
|
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
|
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
11 * the Free Software Foundation, either version 3 of the License, or |
|
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
12 * (at your option) any later version. |
|
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
13 * |
|
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
14 * GNU Emacs is distributed in the hope that it will be useful, |
|
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
17 * GNU General Public License for more details. |
| 105267 | 18 * |
| 19 * You should have received a copy of the GNU General Public License | |
|
107494
bb33285d1ceb
License updates for some test/cedet/tests files.
Glenn Morris <rgm@gnu.org>
parents:
106537
diff
changeset
|
20 * along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
| 105267 | 21 */ |
| 22 | |
| 23 #include <cmath> | |
| 24 | |
| 25 // Test 1 - Functions w/ prototypes | |
| 26 namespace proto { | |
| 27 | |
| 28 int pt_func1(int arg1); | |
| 29 int pt_func1(int arg1) { | |
| 30 return 0; | |
| 31 } | |
| 32 | |
| 33 } | |
| 34 | |
| 35 // Test 2 - Functions w/ different arg lists. | |
| 36 namespace fcn_poly { | |
| 37 | |
| 38 int pm_func(void) { | |
| 39 return 0; | |
| 40 } | |
| 41 int pm_func(int a) { | |
| 42 return a; | |
| 43 } | |
| 44 int pm_func(char a) { | |
| 45 return int(a); | |
| 46 } | |
| 47 int pm_func(double a) { | |
| 48 return int(floor(a)); | |
| 49 } | |
| 50 | |
| 51 } | |
| 52 | |
| 53 // Test 3 - Methods w/ differet arg lists. | |
| 54 class meth_poly { | |
| 55 public: | |
| 56 int pm_meth(void) { | |
| 57 return 0; | |
| 58 } | |
| 59 int pm_meth(int a) { | |
| 60 return a; | |
| 61 } | |
| 62 int pm_meth(char a) { | |
| 63 return int(a); | |
| 64 } | |
| 65 int pm_meth(double a) { | |
| 66 return int(floor(a)); | |
| 67 } | |
| 68 | |
| 69 }; | |
| 70 | |
| 71 // Test 4 - Templates w/ partial specifiers. | |
| 72 namespace template_partial_spec { | |
| 73 template <typename T> class test | |
| 74 { | |
| 75 public: | |
| 76 void doSomething(T t) { }; | |
| 77 }; | |
| 78 | |
| 79 template <typename T> class test<T *> | |
| 80 { | |
| 81 public: | |
| 82 void doSomething(T* t) { }; | |
| 83 }; | |
| 84 } | |
| 85 | |
| 86 // Test 5 - Templates w/ full specicialization which may or may not share | |
| 87 // common functions. | |
| 88 namespace template_full_spec { | |
| 89 template <typename T> class test | |
| 90 { | |
| 91 public: | |
| 92 void doSomething(T t) { }; | |
| 93 void doSomethingElse(T t) { }; | |
| 94 }; | |
| 95 | |
| 96 template <> class test<int> | |
| 97 { | |
| 98 public: | |
| 99 void doSomethingElse(int t) { }; | |
| 100 void doSomethingCompletelyDifferent(int t) { }; | |
| 101 }; | |
| 102 } | |
| 103 | |
| 104 // Test 6 - Dto., but for templates with multiple parameters. | |
| 105 namespace template_multiple_spec { | |
| 106 template <typename T1, typename T2> class test | |
| 107 { | |
| 108 public: | |
| 109 void doSomething(T1 t) { }; | |
| 110 void doSomethingElse(T2 t) { }; | |
| 111 }; | |
| 112 | |
| 113 template <typename T2> class test<int, T2> | |
| 114 { | |
| 115 public: | |
| 116 void doSomething(int t) { }; | |
| 117 void doSomethingElse(T2 t) { }; | |
| 118 }; | |
| 119 | |
| 120 template <> class test<float, int> | |
| 121 { | |
| 122 public: | |
| 123 void doSomething(float t) { }; | |
| 124 void doSomethingElse(int t) { }; | |
| 125 void doNothing(void) { }; | |
| 126 }; | |
| 127 } | |
| 128 | |
| 129 | |
| 130 // End of polymorphism test file. | |
| 105377 | 131 |
