From 52a866baba3cbb05ecf0be88f1b50991b4a26b52 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 15 Apr 2020 09:28:09 +0200 Subject: cpp08 probably done, ex02 has a useless file in this implementation? --- cpp08/ex00/easyfind.hpp | 24 ++++++++++++++++++++++++ cpp08/ex00/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 cpp08/ex00/easyfind.hpp create mode 100644 cpp08/ex00/main.cpp (limited to 'cpp08/ex00') 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +template +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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/15 05:57:10 by charles #+# #+# */ +/* Updated: 2020/04/15 06:47:52 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include "easyfind.hpp" + +int main() +{ + int a[] = {10, 20, 30, 40, 50, 60}; + std::vector b(a, a + 6); + std::list c(a, a + 6); + std::deque 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; +} -- cgit