-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fcil
committed
Sep 13, 2022
1 parent
1759ab5
commit 47f6820
Showing
10 changed files
with
395 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: fcil <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2022/08/03 11:41:37 by fcil #+# #+# # | ||
# Updated: 2022/09/13 00:18:34 by fcil ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME = a.out | ||
CC = c++ -std=c++98 | ||
FLAGS = -Wall -Wextra -Werror | ||
|
||
SRC_DIR = ./ | ||
SRC = $(shell find $(SRC_DIR) -type f -name "*.cpp") | ||
|
||
OBJ = $(SRC:.cpp=.o) | ||
|
||
$(NAME): $(OBJ) | ||
$(CC) $(FLAGS) -o $(NAME) $(OBJ) | ||
|
||
%.o : %.cpp | ||
$(CC) $(FLAGS) -o $@ -c $< | ||
|
||
all: $(NAME) | ||
|
||
clean: | ||
rm -f $(OBJ) | ||
|
||
fclean: clean | ||
rm -f $(NAME) | ||
|
||
re: fclean all | ||
|
||
.PHONY: all clean fclean re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* main.cpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/13 12:13:53 by fcil #+# #+# */ | ||
/* Updated: 2022/09/13 13:36:50 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "whatever.hpp" | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* whatever.hpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/13 12:14:15 by fcil #+# #+# */ | ||
/* Updated: 2022/09/13 13:32:11 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#pragma once | ||
|
||
#include "iostream" | ||
|
||
template<class Type> | ||
void swap(Type &a, Type &b) | ||
{ | ||
Type temp; | ||
temp = a; | ||
a = b; | ||
b = temp; | ||
} | ||
|
||
template<class Type> | ||
Type min(Type &a, Type &b) | ||
{ | ||
return (a < b ? a : b); | ||
} | ||
|
||
template<class Type> | ||
Type max(Type &a, Type &b) | ||
{ | ||
return (a > b ? a : b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: fcil <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2022/08/03 11:41:37 by fcil #+# #+# # | ||
# Updated: 2022/09/13 00:18:34 by fcil ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME = a.out | ||
CC = c++ -std=c++98 | ||
FLAGS = -Wall -Wextra -Werror | ||
|
||
SRC_DIR = ./ | ||
SRC = $(shell find $(SRC_DIR) -type f -name "*.cpp") | ||
|
||
OBJ = $(SRC:.cpp=.o) | ||
|
||
$(NAME): $(OBJ) | ||
$(CC) $(FLAGS) -o $(NAME) $(OBJ) | ||
|
||
%.o : %.cpp | ||
$(CC) $(FLAGS) -o $@ -c $< | ||
|
||
all: $(NAME) | ||
|
||
clean: | ||
rm -f $(OBJ) | ||
|
||
fclean: clean | ||
rm -f $(NAME) | ||
|
||
re: fclean all | ||
|
||
.PHONY: all clean fclean re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* iter.hpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/13 13:37:46 by fcil #+# #+# */ | ||
/* Updated: 2022/09/13 13:38:43 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#pragma once | ||
|
||
#include "iostream" | ||
|
||
template<typename Type> | ||
void iter(Type *array, size_t len, void(*f)(Type const &)) | ||
{ | ||
for (size_t i = 0; i < len; i++) | ||
f(array[i]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* main.cpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/13 13:37:01 by fcil #+# #+# */ | ||
/* Updated: 2022/09/13 13:39:45 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "iter.hpp" | ||
|
||
void print(const int &n) | ||
{ | ||
std::cout << n << " "; | ||
} | ||
|
||
void print2(const std::string &s) | ||
{ | ||
std::cout << s + " "; | ||
} | ||
|
||
int main() | ||
{ | ||
int array[5] = {0, 1, 9, 0, 7}; | ||
iter(array, 5, print); | ||
std::cout << std::endl; | ||
std::string arr[2] = {"test1", "test2"}; | ||
iter(arr, 2, print2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* Array.hpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/13 13:42:33 by fcil #+# #+# */ | ||
/* Updated: 2022/09/13 14:09:06 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#pragma once | ||
#include <iostream> | ||
#include <cstdlib> | ||
|
||
|
||
|
||
template <typename T> | ||
class Array | ||
{ | ||
private: | ||
unsigned int _len; | ||
T *_array; | ||
|
||
public: | ||
Array<T>() | ||
{ | ||
_len = 0; | ||
_array = new T[_len]; | ||
} | ||
|
||
Array<T>(unsigned int len) | ||
{ | ||
_len = len; | ||
_array = new T[_len]; | ||
for (unsigned int i = 0; i < len; i++) | ||
{ | ||
_array[i] = 0; | ||
} | ||
} | ||
|
||
Array<T>(Array &arr) | ||
{ | ||
_len = arr.size(); | ||
_array = new T[_len]; | ||
*this = arr; | ||
for (unsigned int i = 0; i < _len; i++) | ||
{ | ||
_array[i] = arr[i]; | ||
} | ||
} | ||
|
||
~Array<T>() | ||
{ | ||
if (this->_array) | ||
delete [] _array; | ||
} | ||
Array<T> &operator=(const Array &arr) | ||
{ | ||
delete[] _array; | ||
_array = new T[arr.size()]; | ||
_len = arr.size(); | ||
for (unsigned int i = 0; i < _len; i++) | ||
{ | ||
_array[i] = arr[i]; | ||
} | ||
return (*this); | ||
} | ||
|
||
T & operator[](unsigned int i) const | ||
{ | ||
if (i >= this->_len) | ||
throw (Array::outOfLimits()); | ||
return (this->_array[i]); | ||
} | ||
|
||
unsigned int size() const | ||
{ | ||
return this->_len; | ||
} | ||
|
||
class outOfLimits: public std::exception | ||
{ | ||
public: | ||
virtual const char* what() const throw() | ||
{ | ||
return "Index out of limits"; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: fcil <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2022/08/03 11:41:37 by fcil #+# #+# # | ||
# Updated: 2022/09/13 00:18:34 by fcil ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME = a.out | ||
CC = c++ -std=c++98 | ||
FLAGS = -Wall -Wextra -Werror | ||
|
||
SRC_DIR = ./ | ||
SRC = $(shell find $(SRC_DIR) -type f -name "*.cpp") | ||
|
||
OBJ = $(SRC:.cpp=.o) | ||
|
||
$(NAME): $(OBJ) | ||
$(CC) $(FLAGS) -o $(NAME) $(OBJ) | ||
|
||
%.o : %.cpp | ||
$(CC) $(FLAGS) -o $@ -c $< | ||
|
||
all: $(NAME) | ||
|
||
clean: | ||
rm -f $(OBJ) | ||
|
||
fclean: clean | ||
rm -f $(NAME) | ||
|
||
re: fclean all | ||
|
||
.PHONY: all clean fclean re |
Oops, something went wrong.