diff --git a/cpp07/ex00/main.cpp b/cpp07/ex00/main.cpp index db38ed9..9b3a6c5 100644 --- a/cpp07/ex00/main.cpp +++ b/cpp07/ex00/main.cpp @@ -6,11 +6,46 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/08/06 20:20:09 by apommier #+# #+# */ -/* Updated: 2022/08/06 20:20:20 by apommier ### ########.fr */ +/* Updated: 2022/08/06 21:02:04 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ -int main() +#include "whatever.hpp" +#include + +int main( void ) { +//integer + std::cout << "==============INT===============\n"; + int a = 2; + int b = 3; + std::cout << "a = " << a << ", b = " << b << std::endl; + std::cout << "---Swap values---\n"; + ::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::endl; + +//string + std::cout << "==============CHAR===============\n"; + std::string c = "chaine1"; + std::string d = "chaine2"; + std::cout << "c = " << c << ", d = " << d << std::endl; + std::cout << "---Swap values---\n"; + ::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::endl; + +//float + std::cout << "==============FLOAT===============\n"; + float e = 42.042f; + float f = 21.021f; + std::cout << "e = " << e << ", f = " << f << std::endl; + std::cout << "---Swap values---\n"; + ::swap(e, f); + std::cout << "e = " << e << ", f = " << f << std::endl; + std::cout << "min( e, f ) = " << ::min( e, f ) << std::endl; + std::cout << "max( e, f ) = " << ::max( e, f ) << std::endl; return (0); } \ No newline at end of file diff --git a/cpp07/ex00/whatever.hpp b/cpp07/ex00/whatever.hpp index 7f2e225..265373d 100644 --- a/cpp07/ex00/whatever.hpp +++ b/cpp07/ex00/whatever.hpp @@ -6,7 +6,27 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/08/06 20:20:05 by apommier #+# #+# */ -/* Updated: 2022/08/06 20:20:06 by apommier ### ########.fr */ +/* Updated: 2022/08/06 20:55:28 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ +template +void swap(T &x, T &y) +{ + T swap = x; + + x = y; + y = swap; +} + +template +T const &min(T const &x, T const &y) +{ + return ((x < y) ? x : y); +} + +template +T const &max(T const &x, T const &y) +{ + return ((x > y) ? x : y); +} \ No newline at end of file