This commit is contained in:
lfirmin 2026-02-14 09:18:56 +01:00
commit 23d21b42ca
4 changed files with 120 additions and 0 deletions

16
ex00/Easyfind.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef EASYFIND_HPP
#define EASYFIND_HPP
#include <algorithm>
#include <exception>
template <typename T>
typename T::iterator easyfind(T &cont, int val)
{
typename T::iterator it = std::find(cont.begin(), cont.end(), val);
if (it == cont.end())
throw std::exception();
return it;
}
#endif

32
ex00/Main.cpp Normal file
View File

@ -0,0 +1,32 @@
#include "Easyfind.hpp"
#include <iostream>
#include <vector>
#include <list>
int main()
{
std::vector<int> vec;
vec.push_back(10);
vec.push_back(42);
vec.push_back(56);
vec.push_back(87);
std::cout << "Test vector container" << std::endl << "Find 42 (pos 2)" << std::endl;
std::vector<int>::iterator it = easyfind(vec, 42);
std::cout << "Find " << *it << std::endl;
std::list<int> lst;
lst.push_back(10);
lst.push_back(47);
lst.push_back(42);
lst.push_back(87);
std::cout << "Test list container" << std::endl << "Find 42 (pos 3)" << std::endl;
std::list<int>::iterator it2 = easyfind(lst, 42);
std::cout << "Find " << *it2 << std::endl;
std::cout << "Test vector container" << std::endl << "Find 41 (not here !)" << std::endl;
try {
std::vector<int>::iterator it3 = easyfind(vec, 41);
std::cout << "found " << *it3 << std::endl;
} catch (std::exception &e) {
std::cout << "Exeption catch : not found !" << std::endl;
}
}

36
ex00/Makefile Normal file
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 = Easyfind
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

36
ex01/Makefile Normal file
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 = Easyfind
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