iter.hpp
 1  /* ************************************************************************** */
 2  /*                                                                            */
 3  /*                                                        :::      ::::::::   */
 4  /*   iter.hpp                                           :+:      :+:    :+:   */
 5  /*                                                    +:+ +:+         +:+     */
 6  /*   By: gychoi <gychoi@student.42seoul.kr>         +#+  +:+       +#+        */
 7  /*                                                +#+#+#+#+#+   +#+           */
 8  /*   Created: 2023/12/21 01:03:17 by gychoi            #+#    #+#             */
 9  /*   Updated: 2023/12/25 01:46:27 by gychoi           ###   ########.fr       */
10  /*                                                                            */
11  /* ************************************************************************** */
12  
13  #pragma once
14  #ifndef __ITER_HPP__
15  #define __ITER_HPP__
16  
17  #include <iostream>
18  
19  template <typename T, typename F>
20  void	iter(T* arr, size_t len, F const& func)
21  {
22  	for (size_t i = 0; i < len; i++)
23  	{
24  		func(arr[i]);
25  	}
26  }
27  
28  template <typename T, typename F>
29  void	iter(T const* arr, size_t len, F const& func)
30  {
31  	for (size_t i = 0; i < len; i++)
32  	{
33  		func(arr[i]);
34  	}
35  }
36  
37  template <typename T>
38  void	display(T const& a)
39  {
40  	std::cout << a << std::endl;
41  }
42  
43  template<typename T, size_t size>
44  size_t	getArrayLength(T (&)[size])
45  {
46  	return size;
47  }
48  
49  template<typename T, typename F>
50  std::ostream&	operator<<(std::ostream& os, F (*p)(T))
51  {
52  	return os << reinterpret_cast<void*>(p);
53  }
54  
55  #endif /* __ITER_HPP__ */