main.cpp
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* main.cpp :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: gychoi <gychoi@student.42seoul.kr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/12/21 01:02:56 by gychoi #+# #+# */ 9 /* Updated: 2023/12/27 19:01:51 by gychoi ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include <string> 14 #include "iter.hpp" 15 16 int main() 17 { 18 int iArr[] = {1, 2, 3}; 19 20 std::cout << "Testing int array" << std::endl; 21 ::iter(iArr, ::getArrayLength(iArr), ::display<int>); 22 23 std::cout << std::endl; 24 25 std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield); 26 std::cout.precision(2); 27 28 float const cfArr[] = {-0.42f, 2.04f, 3.0f}; 29 30 std::cout << "Testing float const array" << std::endl; 31 ::iter(cfArr, ::getArrayLength(cfArr), ::display<float const>); 32 33 std::cout << std::endl; 34 35 std::string sArr[] = {"hello", "42", "seoul"}; 36 37 std::cout << "Testing string array" << std::endl; 38 ::iter(sArr, ::getArrayLength(sArr), ::display<std::string>); 39 40 std::cout << "\n--------------------\n"; 41 42 void (*fp1)(const int&) 43 = reinterpret_cast<void (*)(const int&)>(&::display<int>); 44 void (*fp2)(const std::string&) 45 = reinterpret_cast<void (*)(const std::string&)> 46 (&::display<std::string>); 47 void (*fp3)(const float&) 48 = reinterpret_cast<void (*)(const float&)>(&::display<float>); 49 void (*fp4)(const int&) 50 = reinterpret_cast<void (*)(const int&)>(&::display<int>); 51 52 std::cout << "Template Function(int) fp1 address: " << fp1 << std::endl; 53 std::cout << "Template Function(string) fp2 address: " << fp2 << std::endl; 54 std::cout << "Template Function(float) fp3 address: " << fp3 << std::endl; 55 std::cout << "Template Function(int) fp4 address: " << fp4 << std::endl; 56 std::cout << "Template made when different type called! Q.E.D" << std::endl; 57 58 return 0; 59 }