diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..ea9a46b --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,26 @@ +CXX := c++ +CXXFLAGS := -std=c++98 -Wall -Wextra -Werror -g +SRCDIR := src +OBJDIR := obj +NAME := ex01 + +SRCS := $(wildcard $(SRCDIR)/*.cpp) +OBJS := $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS)) + +all: $(NAME) + +$(OBJDIR)/%.o: $(SRCDIR)/%.cpp + mkdir -p $(OBJDIR) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(NAME): $(OBJS) + $(CXX) $(CXXFLAGS) $^ -o $@ + +clean: + rm -rf $(OBJDIR) + +fclean: clean + rm -fr $(NAME) + +re: fclean + @make --no-print-directory all \ No newline at end of file diff --git a/ex01/src/iter.hpp b/ex01/src/iter.hpp new file mode 100644 index 0000000..476c666 --- /dev/null +++ b/ex01/src/iter.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include + +template +void iter(T* arr, size_t len, void(*f)(U)) +{ + for (size_t i = 0; i < len; i++) + f(arr[i]); +} \ No newline at end of file diff --git a/ex01/src/main.cpp b/ex01/src/main.cpp new file mode 100644 index 0000000..3a29737 --- /dev/null +++ b/ex01/src/main.cpp @@ -0,0 +1,25 @@ +#include "iter.hpp" +#include + +template +void print(T& t) +{ + std::cout << t << std::endl; +} + +int main() +{ + int array[] = {0, 1, 2, 3, 4, 5, 6}; + + iter(array, 7, print); + + std::string strs[] = { + "Hello World", + "Bonjour Monde", + "Hallo Welt", + "Hola Mundo" + }; + + iter(strs, 4, print); + +} \ No newline at end of file