aboutsummaryrefslogtreecommitdiff
path: root/cpp07/ex01/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp07/ex01/main.cpp')
-rw-r--r--cpp07/ex01/main.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/cpp07/ex01/main.cpp b/cpp07/ex01/main.cpp
index 6ac8e82..3815f77 100644
--- a/cpp07/ex01/main.cpp
+++ b/cpp07/ex01/main.cpp
@@ -6,13 +6,29 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 20:02:19 by charles #+# #+# */
-/* Updated: 2020/12/14 15:16:32 by cacharle ### ########.fr */
+/* Updated: 2020/12/15 11:26:57 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include "iter.hpp"
+NotAnInt::NotAnInt() : m_n(0) {}
+NotAnInt::NotAnInt(int n) : m_n(n) {}
+NotAnInt::NotAnInt(NotAnInt const& other) : m_n(other.m_n) {}
+NotAnInt& NotAnInt::operator=(NotAnInt const& other) { m_n = other.m_n; return *this; }
+int NotAnInt::getN() const { return m_n; }
+
+void intOnly(int n)
+{
+ std::cout << "intOnly() " << n << std::endl;
+}
+
+void notAnIntOnly(NotAnInt& n)
+{
+ std::cout << "notAnIntOnly() " << n.getN() << std::endl;
+}
+
int main()
{
int intArray[] = {1, 2, 3, 4, 10, 20, 30, -1, -2};
@@ -21,6 +37,8 @@ int main()
std::cout << intArray[i] << ", ";
std::cout << std::endl;
iter(intArray, intArraySize, timeTwo<int>);
+ iter(intArray, intArraySize, timeThree<int>);
+ iter(intArray, intArraySize, intOnly);
std::cout << "--------------------------------------" << std::endl;
@@ -30,6 +48,7 @@ int main()
std::cout << floatArray[i] << ", ";
std::cout << std::endl;
iter(floatArray, floatArraySize, timeTwo<float>);
+ iter(floatArray, floatArraySize, timeThree<float>);
std::cout << "--------------------------------------" << std::endl;
@@ -39,6 +58,25 @@ int main()
std::cout << uintArray[i] << ", ";
std::cout << std::endl;
iter(uintArray, uintArraySize, timeTwo<unsigned int>);
+ iter(uintArray, uintArraySize, timeThree<unsigned int>);
+ std::cout << "--------------------------------------" << std::endl;
+
+ const int cintArray[] = {1, 2, 3, 4};
+ size_t cintArraySize = sizeof(cintArray) / sizeof(const int);
+ for (size_t i = 0; i < cintArraySize; i++)
+ std::cout << cintArray[i] << ", ";
+ std::cout << std::endl;
+ iter(cintArray, cintArraySize, timeTwo<const int>);
+ iter(cintArray, cintArraySize, timeThree<const int>);
+
+ std::cout << "--------------------------------------" << std::endl;
+
+ NotAnInt nintArray[] = {NotAnInt(1), NotAnInt(2), NotAnInt(3), NotAnInt(4)};
+ size_t nintArraySize = sizeof(nintArray) / sizeof(NotAnInt);
+ for (size_t i = 0; i < nintArraySize; i++)
+ std::cout << nintArray[i].getN() << ", ";
+ std::cout << std::endl;
+ iter(nintArray, nintArraySize, notAnIntOnly);
return 0;
}