-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathdyad.h
More file actions
69 lines (52 loc) · 1.74 KB
/
dyad.h
File metadata and controls
69 lines (52 loc) · 1.74 KB
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
//*****************************************************************************************************
//
// This header file defines a class template for a dyad, which is a pair of values of the same
// type.
//
//*****************************************************************************************************
#ifndef DYAD_H
#define DYAD_H
//*****************************************************************************************************
template <typename T>
class Dyad {
private:
T val1;
T val2;
public:
Dyad(T v1 = 0, T v2 = 0);
T getFirst() const;
T getSecond() const;
void get2Values(T &v1, T &v2) const;
void swapValues();
};
//*****************************************************************************************************
template <typename T>
Dyad<T>::Dyad(T val1, T val2) {
this->val1 = val1;
this->val2 = val2;
}
//*****************************************************************************************************
template <typename T>
T Dyad<T>::getFirst() const {
return val1;
}
//*****************************************************************************************************
template <typename T>
T Dyad<T>::getSecond() const {
return val2;
}
//*****************************************************************************************************
template <typename T>
void Dyad<T>::get2Values(T &v1, T &v2) const {
v1 = val1;
v2 = val2;
}
//*****************************************************************************************************
template <typename T>
void Dyad<T>::swapValues() {
T temp = val1;
val1 = val2;
val2 = temp;
}
//*****************************************************************************************************
#endif