From 02fe2e779169d698b20490f000210b4b9778b219 Mon Sep 17 00:00:00 2001 From: adjoly Date: Wed, 9 Apr 2025 15:28:52 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E2=9C=A8=E3=80=8D=20feat:=20finished?= =?UTF-8?q?=20ex01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ex01/Makefile | 4 ++-- ex01/iter.hpp | 4 ++-- ex01/main.cpp | 21 +++++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ex01/Makefile b/ex01/Makefile index 902f5c7..ce5503e 100644 --- a/ex01/Makefile +++ b/ex01/Makefile @@ -6,13 +6,13 @@ # By: adjoly +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/10/25 16:09:27 by adjoly #+# #+# # -# Updated: 2025/04/09 14:50:44 by adjoly ### ########.fr # +# Updated: 2025/04/09 15:28:36 by adjoly ### ########.fr # # # # **************************************************************************** # SHELL = bash -NAME = whatever +NAME = iter CC = c++ diff --git a/ex01/iter.hpp b/ex01/iter.hpp index 23c24b6..1e19c75 100644 --- a/ex01/iter.hpp +++ b/ex01/iter.hpp @@ -6,13 +6,13 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/09 14:56:23 by adjoly #+# #+# */ -/* Updated: 2025/04/09 15:21:01 by adjoly ### ########.fr */ +/* Updated: 2025/04/09 15:23:21 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -template void iter(T *arr, int len, void(*func)(T &)) { +template void iter(T *arr, int len, void(func)(T &)) { for (int i = 0; i< len; i++) { func(arr[i]); } diff --git a/ex01/main.cpp b/ex01/main.cpp index ab47724..efde849 100644 --- a/ex01/main.cpp +++ b/ex01/main.cpp @@ -6,21 +6,26 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/09 15:17:59 by adjoly #+# #+# */ -/* Updated: 2025/04/09 15:20:20 by adjoly ### ########.fr */ +/* Updated: 2025/04/09 15:25:40 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "iter.hpp" #include -void test(int &nb) { +void increment(int &nb) { nb++; } -int main(void) { - int test[4] = {1, 2, 3, 4}; - - for (int i = 0; i < 4; i++) { - std::cout << test[i] << std::endl; - } +void printInt(int &nb) { + std::cout << nb << std::endl; +} + +int main(void) { + int arr[4] = {1, 2, 3, 4}; + + iter(arr, 4, printInt); + std::cout << "incrementing" << std::endl; + iter(arr, 4, increment); + iter(arr, 4, printInt); }