aboutsummaryrefslogtreecommitdiff
path: root/cpp08/ex00
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-15 09:28:09 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-15 09:29:39 +0200
commit52a866baba3cbb05ecf0be88f1b50991b4a26b52 (patch)
tree70d32f262c8faddce90ce71cce046019da8b10dd /cpp08/ex00
parent7ac812044bfe771178752a52d70b18bb297c1891 (diff)
downloadpiscine_cpp-52a866baba3cbb05ecf0be88f1b50991b4a26b52.tar.gz
piscine_cpp-52a866baba3cbb05ecf0be88f1b50991b4a26b52.tar.bz2
piscine_cpp-52a866baba3cbb05ecf0be88f1b50991b4a26b52.zip
cpp08 probably done, ex02 has a useless file in this implementation?
Diffstat (limited to 'cpp08/ex00')
-rw-r--r--cpp08/ex00/easyfind.hpp24
-rw-r--r--cpp08/ex00/main.cpp46
2 files changed, 70 insertions, 0 deletions
diff --git a/cpp08/ex00/easyfind.hpp b/cpp08/ex00/easyfind.hpp
new file mode 100644
index 0000000..68e176c
--- /dev/null
+++ b/cpp08/ex00/easyfind.hpp
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* easyfind.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/15 05:53:04 by charles #+# #+# */
+/* Updated: 2020/04/15 06:47:27 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef EASYFIND_HPP
+# define EASYFIND_HPP
+
+# include <algorithm>
+
+template<typename T>
+typename T::iterator easyfind(T& container, int x)
+{
+ return std::find(container.begin(), container.end(), x);
+}
+
+#endif
diff --git a/cpp08/ex00/main.cpp b/cpp08/ex00/main.cpp
new file mode 100644
index 0000000..8824f99
--- /dev/null
+++ b/cpp08/ex00/main.cpp
@@ -0,0 +1,46 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/15 05:57:10 by charles #+# #+# */
+/* Updated: 2020/04/15 06:47:52 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <iostream>
+#include <vector>
+#include <list>
+#include <deque>
+#include "easyfind.hpp"
+
+int main()
+{
+ int a[] = {10, 20, 30, 40, 50, 60};
+ std::vector<int> b(a, a + 6);
+ std::list<int> c(a, a + 6);
+ std::deque<int> d(a, a + 6);
+
+ std::cout << (easyfind(b, 10) != b.end()) << std::endl;
+ std::cout << (easyfind(c, 20) != c.end()) << std::endl;
+ std::cout << (easyfind(d, 30) != d.end()) << std::endl;
+ std::cout << (easyfind(b, 40) != b.end()) << std::endl;
+ std::cout << (easyfind(c, 50) != c.end()) << std::endl;
+ std::cout << (easyfind(d, 60) != d.end()) << std::endl;
+
+ std::cout << *easyfind(b, 10) << std::endl;
+ std::cout << *easyfind(c, 20) << std::endl;
+ std::cout << *easyfind(d, 30) << std::endl;
+ std::cout << *easyfind(b, 40) << std::endl;
+ std::cout << *easyfind(c, 50) << std::endl;
+ std::cout << *easyfind(d, 60) << std::endl;
+
+
+ std::cout << (easyfind(b, 70) != b.end()) << std::endl;
+ std::cout << (easyfind(c, 80) != c.end()) << std::endl;
+ std::cout << (easyfind(d, 90) != d.end()) << std::endl;
+
+ return 0;
+}