aboutsummaryrefslogtreecommitdiff
path: root/cpp07/ex00
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-12-14 15:30:28 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-12-14 15:30:28 +0100
commit1de596dd9242b677d6b47b51db98ce98feb95465 (patch)
treeacbc79883c0af843b8b999a39f96cefd48e6e390 /cpp07/ex00
parentb13cd117a7957f9d86ec2986b47349979325a854 (diff)
downloadpiscine_cpp-1de596dd9242b677d6b47b51db98ce98feb95465.tar.gz
piscine_cpp-1de596dd9242b677d6b47b51db98ce98feb95465.tar.bz2
piscine_cpp-1de596dd9242b677d6b47b51db98ce98feb95465.zip
Updated cpp07 files with new subject
Diffstat (limited to 'cpp07/ex00')
-rw-r--r--cpp07/ex00/Makefile4
-rw-r--r--cpp07/ex00/main.cpp83
-rw-r--r--cpp07/ex00/whatever.hpp (renamed from cpp07/ex00/whatever.cpp)31
3 files changed, 91 insertions, 27 deletions
diff --git a/cpp07/ex00/Makefile b/cpp07/ex00/Makefile
index 660a45b..33feff3 100644
--- a/cpp07/ex00/Makefile
+++ b/cpp07/ex00/Makefile
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/04/14 19:48:34 by charles #+# #+# #
-# Updated: 2020/04/14 19:58:14 by charles ### ########.fr #
+# Updated: 2020/12/14 14:41:32 by cacharle ### ########.fr #
# #
# **************************************************************************** #
@@ -15,7 +15,7 @@ NAME = a_few_functions
CXX = clang++
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
-SRC = whatever.cpp
+SRC = main.cpp
OBJ = $(SRC:.cpp=.o)
all: $(NAME)
diff --git a/cpp07/ex00/main.cpp b/cpp07/ex00/main.cpp
new file mode 100644
index 0000000..1c04faf
--- /dev/null
+++ b/cpp07/ex00/main.cpp
@@ -0,0 +1,83 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/12/14 14:41:39 by cacharle #+# #+# */
+/* Updated: 2020/12/14 15:05:32 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <iostream>
+#include <string>
+#include "whatever.hpp"
+
+int main()
+{
+ {
+ std::cout << "=================== SUBJECT MAIN ================" << std::endl;
+ 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;
+ }
+
+ std::cout << std::endl;
+
+ {
+ double ad = 3.4;
+ double bd = 4.5;
+ float af = 3.4f;
+ float bf = 4.5f;
+ char ac = 'a';
+ char bc = 'b';
+ std::cout << "=================== SWAP ================" << std::endl;
+ ::swap(af, bf);
+ std::cout << "af = " << af << ", bf = " << bf << std::endl;
+ ::swap(ad, bd);
+ std::cout << "ad = " << ad << ", bd = " << bd << std::endl;
+ ::swap(ac, bc);
+ std::cout << "ac = " << ac << ", bc = " << bc << std::endl;
+ }
+
+ std::cout << std::endl;
+
+ double ad = 3.4;
+ double bd = 4.5;
+ float af = 3.4f;
+ float bf = 4.5f;
+ char ac = 'a';
+ char bc = 'b';
+
+
+ int same1 = 4;
+ int same2 = 4;
+
+ std::cout << "=================== MIN ================" << std::endl;
+ std::cout << "min(af, bf) = " << ::min(af, bf) << std::endl;
+ std::cout << "min(ad, bd) = " << ::min(ad, bd) << std::endl;
+ std::cout << "min(ac, bc) = " << ::min(ac, bc) << std::endl;
+ int &minsame = ::min(same1, same2);
+ std::cout << "min(same1, same2) = " << minsame << ", address same2 = " << &same2 << ", address minsame = " << &minsame << std::endl;
+
+ std::cout << std::endl;
+
+ std::cout << "=================== MAX ================" << std::endl;
+ std::cout << "max(af, bf) = " << ::max(af, bf) << std::endl;
+ std::cout << "max(ad, bd) = " << ::max(ad, bd) << std::endl;
+ std::cout << "max(ac, bc) = " << ::max(ac, bc) << std::endl;
+ int &maxsame = ::max(same1, same2);
+ std::cout << "max(same1, same2) = " << maxsame << ", address same2 = " << &same2 << ", address maxsame = " << &maxsame << std::endl;
+
+ return 0;
+}
diff --git a/cpp07/ex00/whatever.cpp b/cpp07/ex00/whatever.hpp
index ebebf8c..8768a44 100644
--- a/cpp07/ex00/whatever.cpp
+++ b/cpp07/ex00/whatever.hpp
@@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* whatever.cpp :+: :+: :+: */
+/* whatever.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 19:46:56 by charles #+# #+# */
-/* Updated: 2020/04/14 20:01:41 by charles ### ########.fr */
+/* Updated: 2020/12/14 15:05:32 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include <iostream>
-#include <string>
+#ifndef WHATEVER_HPP
+# define WHATEVER_HPP
template<typename T>
void swap(T& a, T& b)
{
- T tmp = a;
+ T tmp(a);
a = b;
b = tmp;
}
@@ -33,23 +33,4 @@ T& max(T& a, T& b)
return a > b ? a : b;
}
-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;
-}
+#endif