summaryrefslogtreecommitdiff
path: root/test/cedet/tests/testpolymorph.cpp
blob: 329f4d598f49c8ca47cef62b5c5b7b4a84859fb3 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/** testpolymorph.cpp --- A sequence of polymorphism examples.
 *
 * Copyright (C) 2009, 2010  Free Software Foundation, Inc.
 *
 * Author: Eric M. Ludlam <eric@siege-engine.com>
 *
 * This file is part of GNU Emacs.
 *
 * GNU Emacs is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GNU Emacs is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <cmath>

// Test 1 - Functions w/ prototypes
namespace proto {

  int pt_func1(int arg1);
  int pt_func1(int arg1) {
    return 0;
  }

}

// Test 2 - Functions w/ different arg lists.
namespace fcn_poly {

  int pm_func(void) {
    return 0;
  }
  int pm_func(int a) {
    return a;
  }
  int pm_func(char a) {
    return int(a);
  }
  int pm_func(double a) {
    return int(floor(a));
  }

}

// Test 3 - Methods w/ differet arg lists.
class meth_poly {
public:
  int pm_meth(void) {
    return 0;
  }
  int pm_meth(int a) {
    return a;
  }
  int pm_meth(char a) {
    return int(a);
  }
  int pm_meth(double a) {
    return int(floor(a));
  }

};

// Test 4 - Templates w/ partial specifiers.
namespace template_partial_spec {
  template <typename T> class test
  {
  public:
    void doSomething(T t) { };
  };

  template <typename T> class test<T *>
  {
  public:
    void doSomething(T* t) { };
  };
}

// Test 5 - Templates w/ full specicialization which may or may not share
// common functions.
namespace template_full_spec {
  template <typename T> class test
  {
  public:
    void doSomething(T t) { };
    void doSomethingElse(T t) { };
  };

  template <> class test<int>
  {
  public:
    void doSomethingElse(int t) { };
    void doSomethingCompletelyDifferent(int t) { };
  };
}

// Test 6 - Dto., but for templates with multiple parameters.
namespace template_multiple_spec {
  template <typename T1, typename T2> class test
  {
  public:
    void doSomething(T1 t) { };
    void doSomethingElse(T2 t) { };
  };

  template <typename T2> class test<int, T2>
  {
  public:
    void doSomething(int t) { };
    void doSomethingElse(T2 t) { };
  };

  template <> class test<float, int>
  {
  public:
    void doSomething(float t) { };
    void doSomethingElse(int t) { };
    void doNothing(void) { };
  };
}


// End of polymorphism test file.

// arch-tag: e2c04959-9b3b-4b4f-b9c2-445bf4848aa4