commit 55f136f3e71248d29853ed5566cb0152ac23a1ab Author: Camille Chauvet Date: Mon Sep 25 13:19:15 2023 +0000 add: ex00 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca2e5f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +* +!/**/ +!*.* +!/**/Makefile +*.o diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..47ad482 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,26 @@ +CXX := c++ +CXXFLAGS := -std=c++98 -Wall -Wextra -Werror -g +SRCDIR := src +OBJDIR := obj +NAME := ex00 + +SRCS := $(wildcard $(SRCDIR)/*.cpp) +OBJS := $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS)) + +all: $(NAME) + +$(OBJDIR)/%.o: $(SRCDIR)/%.cpp + mkdir -p obj + $(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 diff --git a/ex00/src/easyfind.hpp b/ex00/src/easyfind.hpp new file mode 100644 index 0000000..a555a69 --- /dev/null +++ b/ex00/src/easyfind.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +template +typename T::iterator easyfind(T& container, int to_find) +{ + return std::find(container.begin(), container.end(), to_find); +} diff --git a/ex00/src/main.cpp b/ex00/src/main.cpp new file mode 100644 index 0000000..da121fe --- /dev/null +++ b/ex00/src/main.cpp @@ -0,0 +1,28 @@ +#include "easyfind.hpp" + +#include +#include +#include + +int main() +{ + std::cout << "------------ std::string -------------" << std::endl; + std::string str("bozoman"); + std::cout << "find b in " << str << ":" << *easyfind(str, 'b') << std::endl; + std::cout << "find r in " << str << ":" << *easyfind(str, 'r') << std::endl; + std::cout << "find n in " << str << ":" << *easyfind(str, 'n') << std::endl; + std::cout << std::endl; + + std::cout << "------------ std::vector -------------" << std::endl; + std::vector vec; + vec.push_back(0); + vec.push_back(1); + vec.push_back(2); + vec.push_back(3); + vec.push_back(4); + vec.push_back(5); + std::cout << "find 0 in " << str << ":" << *easyfind(vec, 0) << std::endl; + std::cout << "find 14 in " << str << ":" << *easyfind(vec, 14) << std::endl; + std::cout << "find 5 in " << str << ":" << *easyfind(vec, 5) << std::endl; + +}