Skip to content

Commit

Permalink
Add increment and decrement operators
Browse files Browse the repository at this point in the history
  • Loading branch information
faheel committed Oct 10, 2017
1 parent 0d5a636 commit 50e78e1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/BigInt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 70 additions & 0 deletions include/operators/increment_decrement.hpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 50e78e1

Please sign in to comment.