commit d65e637f0017d92b93d1ef66eecf21931ff9cdcf Author: starnakin Date: Thu Sep 21 12:17:52 2023 +0200 ex00: init diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..a8b1134 --- /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 $(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/ex00/src/main.cpp b/ex00/src/main.cpp new file mode 100644 index 0000000..8aa6357 --- /dev/null +++ b/ex00/src/main.cpp @@ -0,0 +1,18 @@ +#include "whatever.hpp" +#include + +int main( void ) { + int a = 2; + int b = 3; + ::swap( a, b ); + std::cout << "a = " << a << ", b = " << b << std::endl; + std::cout << "min( a, b ) = " << ::min( a, b ) << std::endl; + std::cout << "max( a, b ) = " << ::max( a, b ) << std::endl; + std::string c = "chaine1"; + std::string d = "chaine2"; + ::swap(c, d); + std::cout << "c = " << c << ", d = " << d << std::endl; + std::cout << "min( c, d ) = " << ::min( c, d ) << std::endl; + std::cout << "max( c, d ) = " << ::max( c, d ) << std::endl; + return 0; +} \ No newline at end of file diff --git a/ex00/src/whatever.hpp b/ex00/src/whatever.hpp new file mode 100644 index 0000000..e77aef7 --- /dev/null +++ b/ex00/src/whatever.hpp @@ -0,0 +1,21 @@ +#pragma once + +template +void swap(T a, T b) +{ + T tmp = a; + a = b; + b = tmp; +} + +template +T min(T a, T b) +{ + return a > b ? a : b; +} + +template +T max(T a, T b) +{ + return a < b ? a : b; +} \ No newline at end of file