diff --git a/d06/ex00/a.out b/d06/ex00/a.out deleted file mode 100755 index aa9fe9d..0000000 Binary files a/d06/ex00/a.out and /dev/null differ diff --git a/d06/ex00/convert b/d06/ex00/convert deleted file mode 100755 index 4a8e4c3..0000000 Binary files a/d06/ex00/convert and /dev/null differ diff --git a/d06/ex00/test_float.cpp b/d06/ex00/test_float.cpp deleted file mode 100644 index 8b2447e..0000000 --- a/d06/ex00/test_float.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include -#include - -#define MAX_INT 2147483647 -#define MIN_INT -2147483648 -#define MAX_FLOAT 340282346638528859811704183484516925440.0f -#define MIN_FLOAT -340282346638528859811704183484516925440.0f - -void isFloat(double d) { - if (! (d <= std::numeric_limits::max() - && d >= std::numeric_limits::min()) ) - { - std::cout << d << "is outside range of floats\n"; - return ; - } - std::cout << std::fixed << static_cast(d) << "\n"; -} - -int main() { - - double d; - double d2; - - d = std::numeric_limits::max(); - std::cout << std::fixed << d << "\n"; - d2 = std::nextafter(d, DBL_MAX); - std::cout << std::fixed << d2 << "\n"; -// isFloat(MAX_FLOAT); -// d = std::numeric_limits::lowest(); -// std::cout << std::fixed << d << "\n"; -// isFloat(d); - - return 0; -} diff --git a/d07/ex00/Makefile b/d07/ex00/Makefile new file mode 100644 index 0000000..ca18bd1 --- /dev/null +++ b/d07/ex00/Makefile @@ -0,0 +1,75 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value \ . += append to a variable # +# VARIABLES . value . != set result of command # +# . name is case sensitive . ?= set if not already set # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = templates + +#TYPE = c +TYPE = cpp + +ifeq "$(TYPE)" "c" + CC = c + EXT = c +else ifeq "$(TYPE)" "cpp" + CC = c++ + EXT = cpp +endif + +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) +ifeq "$(TYPE)" "cpp" + CFLAGS += -std=c++98 +endif + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = . +SRCS = main.cpp + +D_HEADERS = headers +HEADERS = Templates.hpp + +D_OBJS = builds +OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) + +ifeq "$(D_OBJS)" "." + RM_OBJS = rm -f $(OBJS) +else + RM_OBJS = rm -rf $(D_OBJS) +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) + $(CC) $(OBJS) -o $@ $(LIBS) + +clean: + $(RM_OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY : all clean fclean re + diff --git a/d07/ex00/headers/Templates.hpp b/d07/ex00/headers/Templates.hpp new file mode 100644 index 0000000..ad4bc1a --- /dev/null +++ b/d07/ex00/headers/Templates.hpp @@ -0,0 +1,28 @@ +#ifndef TEMPLATES_HPP +# define TEMPLATES_HPP + +template< typename T > +void swap(T &a, T &b) { + + T tmp; + + tmp = a; + a = b; + b = tmp; +} + +template< typename T > +T const & min(T const &a, T const &b) { + if (a < b) + return a; + return b; +} + +template< typename T > +T const & max(T const &a, T const &b) { + if (a > b) + return a; + return b; +} + +#endif diff --git a/d07/ex00/main.cpp b/d07/ex00/main.cpp new file mode 100644 index 0000000..434f440 --- /dev/null +++ b/d07/ex00/main.cpp @@ -0,0 +1,24 @@ +#include +#include +#include "Templates.hpp" + +int main() { + 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; +} + diff --git a/d07/ex00/templates b/d07/ex00/templates new file mode 100755 index 0000000..04b4266 Binary files /dev/null and b/d07/ex00/templates differ