push_final

This commit is contained in:
root
2026-02-04 02:08:57 +00:00
parent cd9912e9fc
commit b605c0bc52
6 changed files with 297 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
#ifndef ITER_HPP
#define ITER_HPP
#include <iostream>
template <typename Func, typename Arr>
void iter(Arr *ptr, size_t len, Func fonction)
{
size_t i = 0;
while (i < len)
fonction(ptr[i++]);
}
#endif
+27
View File
@@ -0,0 +1,27 @@
#include "Iter.hpp"
void print(std::string &str)
{
std::cout << str << std::endl;
}
void afficherConst(const int &nb)
{
std::cout << nb << std::endl;
}
void add_one(int nb)
{
std::cout << nb+1 << std::endl;
}
int main()
{
std::string tab[] = {"Hello", ", ", "World ", "!"};
iter(tab, 4, print);
std::cout << std::endl;
int tab2[] = {1, 2, 3, 41};
iter(tab2, 4, add_one);
std::cout << std::endl;
iter(tab2, 4, afficherConst);
return 0;
}
+36
View File
@@ -0,0 +1,36 @@
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
SOURCES = Main.cpp
OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o))
NAME = Iter
all: $(NAME)
$(OBJDIR):
@echo "📁 Creating obj directory..."
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@echo "🧠 Compiling $< ..."
@$(CXX) $(CXXFLAGS) -c $< -o $@
@echo "$@ ready!"
$(NAME): $(OBJECTS)
@echo "🔗 Linking $(NAME) ..."
@$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME)
@echo "🎉 $(NAME) is ready!"
clean:
@echo "🧹 Cleaning object files..."
@rm -rf $(OBJDIR)
@echo "✨ Objects cleaned!"
fclean: clean
@echo "🗑️ Removing $(NAME)..."
@rm -f $(NAME)
@echo "💀 Full clean complete!"
re: fclean all
.PHONY: all clean fclean re