aboutsummaryrefslogtreecommitdiff
path: root/cpp08/ex02/mutantstack.hpp
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-12-15 14:25:57 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-12-15 14:25:57 +0100
commit4115f22c50ee0571e88a8ec44c0241693af7ed38 (patch)
tree9e702e34ba360aa5f10f8f84b37b97b6ca8dd731 /cpp08/ex02/mutantstack.hpp
parent78efa932fb42289904fe542cfc152978397ae37c (diff)
downloadpiscine_cpp-4115f22c50ee0571e88a8ec44c0241693af7ed38.tar.gz
piscine_cpp-4115f22c50ee0571e88a8ec44c0241693af7ed38.tar.bz2
piscine_cpp-4115f22c50ee0571e88a8ec44c0241693af7ed38.zip
Fixing cpp08/{00,01}
Diffstat (limited to 'cpp08/ex02/mutantstack.hpp')
-rw-r--r--cpp08/ex02/mutantstack.hpp84
1 files changed, 22 insertions, 62 deletions
diff --git a/cpp08/ex02/mutantstack.hpp b/cpp08/ex02/mutantstack.hpp
index 2cbeb9e..56a5bbf 100644
--- a/cpp08/ex02/mutantstack.hpp
+++ b/cpp08/ex02/mutantstack.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/15 07:29:42 by charles #+# #+# */
-/* Updated: 2020/04/15 09:25:55 by charles ### ########.fr */
+/* Updated: 2020/12/15 14:21:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,43 +15,38 @@
# include <stack>
-template<typename T>
+template <typename T>
class MutantStack : public std::stack<T>
{
public:
- MutantStack() : std::stack<T>()
- {}
+ MutantStack() : std::stack<T>() {}
- MutantStack(MutantStack const& other) : std::stack<T>(other)
- {}
+ MutantStack(MutantStack const& other) : std::stack<T>(other) {}
- void operator=(MutantStack const& other)
+ MutantStack& operator=(MutantStack const& other)
{
std::stack<T>::operator=(other);
+ return *this;
}
- ~MutantStack()
- {}
+ ~MutantStack() {}
class iterator
{
public:
iterator(iterator const& other)
- : m_parentStack(other.m_parentStack), m_pos(other.m_pos)
- {}
+ : m_parentStack(other.m_parentStack), m_pos(other.m_pos) {}
void operator=(iterator const& other)
{
m_parentStack = other.m_parentStack;
- m_pos = other.m_pos;
+ m_pos = other.m_pos;
}
- ~iterator()
- {}
+ ~iterator() {}
iterator(MutantStack<T>& parentStack, unsigned int n)
- : m_parentStack(parentStack), m_pos(n)
- {}
+ : m_parentStack(parentStack), m_pos(n) {}
T& operator*()
{
@@ -70,61 +65,26 @@ public:
}
return res;
}
- // T& operator->();
- // pre increment;
- iterator& operator++()
- {
- m_pos++;
- return *this;
- }
-
- // post increment;
- iterator& operator++(int)
- {
- m_pos++;
- return *this;
- }
-
- iterator& operator--()
- {
- m_pos--;
- return *this;
- }
-
- iterator& operator--(int)
- {
- m_pos--;
- return *this;
- }
+ T* operator->() { return &(*(*this)); }
- bool operator==(iterator const& right)
- {
- return m_pos == right.m_pos;
- }
+ iterator& operator++() { m_pos++; return *this; }
+ iterator& operator++(int) { m_pos++; return *this; }
+ iterator& operator--() { m_pos--; return *this; }
+ iterator& operator--(int) { m_pos--; return *this; }
- bool operator!=(iterator const& right)
- {
- return !(*this == right);
- }
+ bool operator==(iterator const& right) { return m_pos == right.m_pos; }
+ bool operator!=(iterator const& right) { return !(*this == right); }
private:
- iterator() : m_pos(0)
- {}
+ iterator() : m_pos(0) {}
MutantStack<T>& m_parentStack;
- int m_pos;
+ int m_pos;
};
- iterator begin()
- {
- return iterator(*this, 0);
- }
-
- iterator end()
- {
- return iterator(*this, this->size());
- }
+ iterator begin() { return iterator(*this, 0); }
+ iterator end() { return iterator(*this, this->size()); }
};
#endif