main.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* main.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2026/01/13 17:54:18 by bchanot #+# #+# */
  9. /* Updated: 2026/01/13 18:03:54 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include <iostream>
  13. #include <vector>
  14. #include <iterator>
  15. template< typename T >
  16. std::vector<int>::iterator easyFind(T & vec, int const & j) {
  17. std::vector<int>::iterator it;
  18. for (it = std::begin(vec); it < std::end(vec); it++) {
  19. if (*it == j)
  20. return it;
  21. }
  22. throw std::exception();
  23. }
  24. int main(void)
  25. {
  26. std::vector<int> vec = {0, 23, 456, 67};
  27. std::vector<int>::iterator it;
  28. try {
  29. it = easyFind(vec, 22);
  30. std::cout << "Found ! it is : " << *it << std::endl;
  31. } catch (std::exception &e) {
  32. std::cout << "Didn't found the given int in the vec" << std::endl;
  33. }
  34. return 0;
  35. }