forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbasics.hpp
119 lines (98 loc) · 2.39 KB
/
basics.hpp
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
#pragma once
namespace test {
// C++ function
int testFunc(char c);
// Struct
struct testStruct
{
float f;
char c;
unsigned n;
};
// Global variables
extern double testDoubleVar;
extern testStruct testVar;
// Simple class with virtual functions
class testClass
{
// protected:
// testStruct priv;
public:
testStruct priv;
unsigned n;
virtual int echo(int a, int b);
virtual float echo2(float f);
testClass() { n = 1000; }
};
// Derived class
class testInherit : public testClass
{
public:
float f;
char c;
int echo(int a, int b) override;
virtual float echo2(float f) override;
testInherit() { n = 5; }
};
// Multiple inheritance
class anotherClass
{
public:
int number;
float floating;
double doubling;
virtual const char *hello(bool ceres);
};
class testMultipleInherit : public anotherClass,
public testInherit
{
public:
testStruct *pointerToStruct;
virtual const char *hello(bool pluto) override;
};
// Enum
enum enumTest
{
ENUM_FIRSTVAL = 2,
ENUM_SOMEVAL,
ENUM_LASTVAL
};
// Class template and array
template<typename T>
class arrayOfTen
{
public:
T someArray[10];
T FifthChar() { return someArray[4]; }
};
// Partial and explicit template specializations
template<typename T = unsigned, int N = 1> // primary template
struct tempWithPartialSpecs
{
const char *toChars() { return "Primary template"; }
};
template<typename T>
struct tempWithPartialSpecs<T, 0>
{
const char *toChars() { return "Partial spec (N = 0)"; }
};
template<typename T>
struct tempWithPartialSpecs<T, 5>
{
const char *toChars() { return "Partial spec (N = 5)"; }
};
template<int N>
struct tempWithPartialSpecs<char, N>
{
const char *toChars() { return "Partial spec (T = char)"; }
};
template<>
class tempWithPartialSpecs<bool, 5> // explicit spec
{
public:
const char *toChars() { return "Explicit spec (T = bool, N = 5)"; }
};
// Function templates
template<typename T>
unsigned funcTempSizeOf(T a) { return sizeof(T); }
}