commit ab04a0f8fa0cf32d23326e3d83a53f4595fe8cbb Author: aortigos Date: Fri Apr 17 21:00:49 2026 +0200 ex00 diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..f377f12 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,43 @@ +NAME = easyfind + +SRC = main.cpp + + +OBJ = $(SRC:.cpp=.o) + +CC = c++ +CFLAGS = -Wall -Wextra -Werror -std=c++98 + +GREEN = \033[0;32m +RED = \033[0;31m +RESET = \033[0m + +TOTAL := $(words $(SRC)) +COUNT = 0 + +all: $(NAME) + +$(NAME): $(OBJ) + @rm -f .build_start + @$(CC) $(CFLAGS) $(OBJ) -o $(NAME) + @printf "\n$(GREEN)✔ Listo (100%%)\n$(RESET)" + +%.o: %.cpp + @if [ ! -f .build_start ]; then printf "$(GREEN)Compilando archivos...\n$(RESET)"; touch .build_start; fi + @$(eval COUNT = $(shell echo $$(($(COUNT)+1)))) + @PERCENT=$$(($(COUNT)*100/$(TOTAL))); \ + BAR=$$(printf "%0.s#" $$(seq 1 $$((PERCENT/5)))); \ + SPACE=$$(printf "%0.s " $$(seq 1 $$((20-PERCENT/5)))); \ + printf "\r [$$BAR$$SPACE] %3d%% (%d/%d) $< " $$PERCENT $(COUNT) $(TOTAL) + @$(CC) $(CFLAGS) -c $< -o $@ + +clean: + @printf "$(RED)Eliminando...\n$(RESET)" + @rm -f $(OBJ) + +fclean: clean + @rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex00/easyfind.hpp b/ex00/easyfind.hpp new file mode 100644 index 0000000..4126a72 --- /dev/null +++ b/ex00/easyfind.hpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* easyfind.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#include + +template +typename T::iterator easyfind(T array, int nb) +{ + for(typename T::iterator it = array.begin(); + it != array.end(); + it++) + { + if (*it == nb) + { + return (it); + } + } + throw std::exception(); +} \ No newline at end of file diff --git a/ex00/main.cpp b/ex00/main.cpp new file mode 100644 index 0000000..cc56811 --- /dev/null +++ b/ex00/main.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos arr; + + arr.push_back(5); + arr.push_back(4); + arr.push_back(3); + arr.push_back(2); + + std::cout << *easyfind(arr, 4) << std::endl; + + return (0); +} \ No newline at end of file