diff --git a/include/BigInt.hpp b/include/BigInt.hpp index 0313c27..d79414a 100644 --- a/include/BigInt.hpp +++ b/include/BigInt.hpp @@ -65,10 +65,10 @@ class BigInt { BigInt& operator%=(const std::string&); // TODO // Increment and decrement operators: - BigInt& operator++(); // pre-increment TODO - BigInt& operator--(); // pre-decrement TODO - BigInt operator++(int); // post-increment TODO - BigInt operator--(int); // post-decrement TODO + BigInt& operator++(); // pre-increment + BigInt& operator--(); // pre-decrement + BigInt operator++(int); // post-increment + BigInt operator--(int); // post-decrement // Relational operators: bool operator<(const BigInt&) const; diff --git a/include/operators/increment_decrement.hpp b/include/operators/increment_decrement.hpp new file mode 100644 index 0000000..1037820 --- /dev/null +++ b/include/operators/increment_decrement.hpp @@ -0,0 +1,70 @@ +/* + =========================================================================== + Increment and decrement operators + =========================================================================== +*/ + +#ifndef BIG_INT_INCREMENT_DECREMENT_OPERATORS_HPP +#define BIG_INT_INCREMENT_DECREMENT_OPERATORS_HPP + +#include "BigInt.hpp" +#include "constructors/constructors.hpp" +#include "operators/assignment.hpp" +#include "operators/arithmetic_assignment.hpp" +#include "operators/binary_arithmetic.hpp" + + +/* + Pre-increment + ------------- + ++BigInt +*/ + +BigInt& BigInt::operator++() { + *this += 1; + + return *this; +} + + +/* + Pre-decrement + ------------- + --BigInt +*/ + +BigInt& BigInt::operator--() { + *this -= 1; + + return *this; +} + + +/* + Post-increment + -------------- + BigInt++ +*/ + +BigInt BigInt::operator++(int) { + BigInt temp = *this; + *this += 1; + + return temp; +} + + +/* + Post-decrement + -------------- + BigInt-- +*/ + +BigInt BigInt::operator--(int) { + BigInt temp = *this; + *this -= 1; + + return temp; +} + +#endif // BIG_INT_INCREMENT_DECREMENT_OPERATORS_HPP