ex00: init
This commit is contained in:
commit
d65e637f00
26
ex00/Makefile
Normal file
26
ex00/Makefile
Normal file
@ -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
|
18
ex00/src/main.cpp
Normal file
18
ex00/src/main.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "whatever.hpp"
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
21
ex00/src/whatever.hpp
Normal file
21
ex00/src/whatever.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
template <typename T>
|
||||
void swap(T a, T b)
|
||||
{
|
||||
T tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T min(T a, T b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T max(T a, T b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
Loading…
Reference in New Issue
Block a user