MCPcopy Create free account
hub / github.com/andreasfertig/programming-with-cpp20 / MedicalRecordNumber

Class MedicalRecordNumber

06.04-equalComparOfMRN2/main.cpp:6–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <cstdint>
5
6class MedicalRecordNumber {
7public:
8 MedicalRecordNumber() = default;
9 explicit MedicalRecordNumber(uint64_t mrn)
10 : mMRN{mrn}
11 {}
12
13 // #A The initial member functions
14 bool operator==(const MedicalRecordNumber& other) const
15 {
16 return mMRN == other.mMRN;
17 }
18
19 bool operator!=(const MedicalRecordNumber& other) const
20 {
21 return !(*this == other);
22 }
23
24 // #B The additional overloads for uint64_t
25 friend bool operator==(const MedicalRecordNumber& rec,
26 const uint64_t& num)
27 {
28 return rec.mMRN == num;
29 }
30
31 friend bool operator!=(const MedicalRecordNumber& rec,
32 const uint64_t& num)
33 {
34 return !(rec == num);
35 }
36
37 // #C The additional overloads with swapped arguments for uint64_t
38 friend bool operator==(const uint64_t& num,
39 const MedicalRecordNumber& rec)
40 {
41 return (rec == num);
42 }
43
44 friend bool operator!=(const uint64_t& num,
45 const MedicalRecordNumber& rec)
46 {
47 return !(rec == num);
48 }
49
50private:
51 uint64_t mMRN;
52};
53
54int main()
55{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected