To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 78eea530 authored by Erick Turricelli's avatar Erick Turricelli
Browse files

Operator overloading

parent 0c113bda
......@@ -10,33 +10,72 @@ template<class T>
T identity_element() { return T(1); }
// to be implemented: specialize the previous function for Z2
template<>
Z2 identity_element() {
return Plus;
}
Z2 operator*(const Z2 a, const Z2 b)
{
// to be implemented
if( (a == Plus && b == Plus) || (a == Minus && b == Minus)) {
return Plus;
}
else {
return Minus;
}
}
std::ostream& operator<<(std::ostream& os, const Z2 a)
{
// to be implemented
if(a == Plus) {
return os << "Plus ";
}
else {
return os << "Minus";
}
}
template<class T>
T operator*(const T a, const Z2 b)
{
// to be implemented
if(b == Plus ) {
return a;
}
else {
return -a;
}
}
template<class T>
T operator*(const Z2 b, const T a)
{
// to be implemented
if(b == Plus ) {
return a;
}
else {
return -a;
}
}
template<class T>
T mypow(T a, const unsigned int n)
{
// to be implemented
if (n==0) {
return identity_element<T>();
}
unsigned int i = 1;
T result = a;
while (i < n) {
i++;
result = result * a;
}
return result;
}
int main()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment