(fatal): Add a final \n if needed (bug#5596).
[emacs.git] / test / cedet / tests / testpolymorph.cpp
blob51f933cf7fdb747333a91ccdb549ab367666d1bc
1 /** testpolymorph.cpp --- A sequence of polymorphism examples.
3 * Copyright (C) 2009 Eric M. Ludlam
5 * Author: Eric M. Ludlam <eric@siege-engine.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2, or (at
10 * your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #include <cmath>
25 // Test 1 - Functions w/ prototypes
26 namespace proto {
28 int pt_func1(int arg1);
29 int pt_func1(int arg1) {
30 return 0;
35 // Test 2 - Functions w/ different arg lists.
36 namespace fcn_poly {
38 int pm_func(void) {
39 return 0;
41 int pm_func(int a) {
42 return a;
44 int pm_func(char a) {
45 return int(a);
47 int pm_func(double a) {
48 return int(floor(a));
53 // Test 3 - Methods w/ differet arg lists.
54 class meth_poly {
55 public:
56 int pm_meth(void) {
57 return 0;
59 int pm_meth(int a) {
60 return a;
62 int pm_meth(char a) {
63 return int(a);
65 int pm_meth(double a) {
66 return int(floor(a));
71 // Test 4 - Templates w/ partial specifiers.
72 namespace template_partial_spec {
73 template <typename T> class test
75 public:
76 void doSomething(T t) { };
79 template <typename T> class test<T *>
81 public:
82 void doSomething(T* t) { };
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
91 public:
92 void doSomething(T t) { };
93 void doSomethingElse(T t) { };
96 template <> class test<int>
98 public:
99 void doSomethingElse(int t) { };
100 void doSomethingCompletelyDifferent(int t) { };
104 // Test 6 - Dto., but for templates with multiple parameters.
105 namespace template_multiple_spec {
106 template <typename T1, typename T2> class test
108 public:
109 void doSomething(T1 t) { };
110 void doSomethingElse(T2 t) { };
113 template <typename T2> class test<int, T2>
115 public:
116 void doSomething(int t) { };
117 void doSomethingElse(T2 t) { };
120 template <> class test<float, int>
122 public:
123 void doSomething(float t) { };
124 void doSomethingElse(int t) { };
125 void doNothing(void) { };
130 // End of polymorphism test file.
132 // arch-tag: e2c04959-9b3b-4b4f-b9c2-445bf4848aa4