| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* main.cpp :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2026/01/13 17:54:18 by bchanot #+# #+# */
- /* Updated: 2026/01/13 18:03:54 by bchanot ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include <iostream>
- #include <vector>
- #include <iterator>
- template< typename T >
- std::vector<int>::iterator easyFind(T & vec, int const & j) {
- std::vector<int>::iterator it;
- for (it = std::begin(vec); it < std::end(vec); it++) {
- if (*it == j)
- return it;
- }
- throw std::exception();
- }
- int main(void)
- {
- std::vector<int> vec = {0, 23, 456, 67};
- std::vector<int>::iterator it;
- try {
- it = easyFind(vec, 22);
- std::cout << "Found ! it is : " << *it << std::endl;
- } catch (std::exception &e) {
- std::cout << "Didn't found the given int in the vec" << std::endl;
- }
- return 0;
- }
|