-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwith_multiplicity.h
More file actions
90 lines (71 loc) · 2 KB
/
with_multiplicity.h
File metadata and controls
90 lines (71 loc) · 2 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// Created by shama on 15.04.2023.
//
#ifndef VKR_WITH_MULTIPLICITY_H
#define VKR_WITH_MULTIPLICITY_H
#include <exception>
#include <iostream>
#include <sstream>
#include "defines.h"
struct MultiplicityException : std::exception {
unsigned long long value;
explicit MultiplicityException(unsigned long long value) : value(value) {}
};
template<typename ValueType>
struct WithMultiplicity {
ValueType value;
unsigned long long multiplicity;
explicit WithMultiplicity(ValueType v = {}) : value(v), multiplicity(1) {};
WithMultiplicity& operator,(WithMultiplicity other) {
multiplicity += other.multiplicity;
return *this;
};
WithMultiplicity& operator*=(auto other) {
value *= other;
return *this;
}
WithMultiplicity operator*(auto other) const {
WithMultiplicity res = *this;
res *= other;
return res;
}
WithMultiplicity& operator+=(auto other) {
value += other;
return *this;
}
WithMultiplicity operator+(auto other) const {
WithMultiplicity res = *this;
res += other;
return res;
}
COMPARABLE_AS(value, other.value)
ValueType operator-(ValueType other) const {
return value - other;
}
explicit operator ValueType() {
return value;
}
};
template<typename ValueType>
std::ostream& operator<<(std::ostream& out, const WithMultiplicity<ValueType>& v) {
return out << v.value << ' ' << v.multiplicity;
}
class MultiplicityChecker {
bool m_success = true;
public:
~MultiplicityChecker() {
std::stringstream output;
output << (m_success ? "No multiplicity found" : "Multiplicity found") << std::endl;
std::cout << output.str();
}
template<typename ValueType>
bool operator()(WithMultiplicity<ValueType> v) {
if (v.multiplicity > 1) {
m_success = false;
return true;
} else {
return false;
}
}
};
#endif //VKR_WITH_MULTIPLICITY_H