iter.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* iter.hpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2026/01/09 14:24:10 by bchanot #+# #+# */
  9. /* Updated: 2026/01/09 18:42:40 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #ifndef ITER_HPP
  13. # define ITER_HPP
  14. # include <iostream>
  15. # include <string>
  16. template < typename T >
  17. void iter(T const *array, size_t size, void (*fn)(T const &)) {
  18. size_t i;
  19. i = 0;
  20. while (i < size)
  21. fn(array[i++]);
  22. }
  23. template < typename T >
  24. void iter(T const *array, size_t size, void (*fn)(T &)) {
  25. size_t i;
  26. T *tmp;
  27. tmp = const_cast<T*>(array);
  28. i = 0;
  29. while (i < size)
  30. fn(tmp[i++]);
  31. }
  32. template < typename T >
  33. void iter(T *array, size_t size, void (*fn)(T &)) {
  34. size_t i;
  35. i = 0;
  36. while (i < size)
  37. fn(array[i++]);
  38. }
  39. void print(int & value) {
  40. std::cout << "print " << value << std::endl;
  41. }
  42. template < typename T >
  43. void printConst(T const & value) {
  44. std::cout << "print " << value << std::endl;
  45. }
  46. template < typename T >
  47. void addTen(T & a) {
  48. a += 10;
  49. }
  50. #endif