/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/15 07:30:43 by charles #+# #+# */ /* Updated: 2020/12/17 11:22:07 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include "mutantstack.hpp" int main() { { std::cout << "=================== SUBJECT MAIN ======================" << std::endl; { MutantStack mstack; mstack.push(5); mstack.push(17); std::cout << mstack.top() << std::endl; mstack.pop(); std::cout << mstack.size() << std::endl; mstack.push(3); mstack.push(5); mstack.push(737); mstack.push(0); MutantStack::iterator it = mstack.begin(); MutantStack::iterator ite = mstack.end(); ++it; --it; while (it != ite) { std::cout << *it << std::endl; ++it; } std::stack s(mstack); } std::cout << "-----------------------------------------------------" << std::endl; { std::list mstack; mstack.push_back(5); mstack.push_back(17); std::cout << mstack.back() << std::endl; mstack.pop_back(); std::cout << mstack.size() << std::endl; mstack.push_back(3); mstack.push_back(5); mstack.push_back(737); mstack.push_back(0); std::list::iterator it = mstack.begin(); std::list::iterator ite = mstack.end(); ++it; --it; while (it != ite) { std::cout << *it << std::endl; ++it; } std::list s(mstack); } } std::cout << std::endl; { std::cout << "=================== METHODS ======================" << std::endl; std::cout << "------------------- DEFAULT CONSTRUCTOR" << std::endl; MutantStack a; std::cout << a.empty() << std::endl; std::cout << a.size() << std::endl; a.push(1); a.push(2); a.push(3); std::cout << a.empty() << std::endl; std::cout << a.size() << std::endl; std::cout << a.top() << std::endl; std::cout << "------------------- COPY CONSTRUCTOR" << std::endl; MutantStack b(a); std::cout << b.empty() << std::endl; std::cout << b.size() << std::endl; std::cout << b.top() << std::endl; b.push(4); std::cout << b.top() << std::endl; std::cout << a.top() << std::endl; std::cout << "------------------- ASSIGN" << std::endl; MutantStack c; c.push(-1); c = a; std::cout << c.empty() << std::endl; std::cout << c.size() << std::endl; std::cout << c.top() << std::endl; c.push(4); std::cout << c.top() << std::endl; std::cout << a.top() << std::endl; std::cout << "------------------- POP" << std::endl; a.pop(); a.pop(); std::cout << a.empty() << std::endl; std::cout << a.size() << std::endl; std::cout << a.top() << std::endl; std::cout << "------------------- COMPARISON" << std::endl; std::cout << (a == b) << std::endl; std::cout << (a != c) << std::endl; std::cout << (a < c ) << std::endl; std::cout << (a > c ) << std::endl; std::cout << (a <= c) << std::endl; std::cout << (a >= c) << std::endl; } std::cout << std::endl; { std::cout << "=================== ITERATOR ======================" << std::endl; MutantStack a; a.push(1.1f); a.push(2.2f); a.push(3.3f); std::cout << "------------------- PRE INCREMENT" << std::endl; for (MutantStack::iterator it = a.begin(); it != a.end(); ++it) std::cout << *it << std::endl; std::cout << "------------------- POST INCREMENT" << std::endl; for (MutantStack::iterator it = a.begin(); it != a.end(); it++) std::cout << *it << std::endl; std::cout << "------------------- PRE DECREMENT" << std::endl; for (MutantStack::iterator it = --a.end(); it != a.begin(); --it) std::cout << *it << std::endl; std::cout << "------------------- POST DECREMENT" << std::endl; for (MutantStack::iterator it = --a.end(); it != a.begin(); it--) std::cout << *it << std::endl; std::cout << "------------------- ARROW OPERATOR" << std::endl; MutantStack::iterator it_arrow = a.begin(); std::cout << it_arrow.operator->() << std::endl; std::cout << *(it_arrow.operator->()) << std::endl; std::cout << "------------------- PRE INCREMENT / DEREF" << std::endl; for (MutantStack::iterator it = a.begin(); it != --a.end();) std::cout << (*++it) << std::endl; std::cout << "------------------- POST INCREMENT / DEREF" << std::endl; for (MutantStack::iterator it = a.begin(); it != --a.end();) std::cout << *it++ << std::endl; std::cout << "------------------- COMPARISON" << std::endl; std::cout << (a.begin() == a.end()) << std::endl; std::cout << (a.begin() != a.end()) << std::endl; std::cout << "------------------- COPY CONSTRUCTOR" << std::endl; MutantStack::iterator it_copied = ++a.begin(); MutantStack::iterator it_copy(it_copied); std::cout << *it_copied << std::endl; std::cout << *it_copy << std::endl; std::cout << "------------------- ASSIGNMENT" << std::endl; MutantStack::iterator it_assign(a.begin()); it_assign = it_copied; std::cout << *it_copied << std::endl; std::cout << *it_assign << std::endl; std::cout << "------------------- ITERATOR ASSIGN" << std::endl; for (MutantStack::iterator it = a.begin(); it != a.end(); ++it) *it = 4.4f; for (MutantStack::iterator it = a.begin(); it != a.end(); ++it) std::cout << *it << std::endl; std::cout << "------------------- MORE" << std::endl; MutantStack d; d.push(0.5f); d.push(1.5f); d.push(2.5f); d.push(3.5f); d.push(4.5f); d.push(5.5f); d.push(6.5f); d.push(7.5f); d.push(8.5f); d.push(9.5f); d.push(1.9f); for (MutantStack::iterator it = d.begin(); it != d.end(); ++it) std::cout << *it << std::endl; std::cout << "------------------- REVERSE" << std::endl; for (MutantStack::reverse_iterator it = d.rbegin(); it != d.rend(); ++it) std::cout << *it << std::endl; } return 0; }