start cpp07 ex00

This commit is contained in:
Alexandre POMMIER 2022-08-07 14:05:08 +02:00
parent 113fd038c8
commit 5509371f35
2 changed files with 58 additions and 3 deletions

View File

@ -6,11 +6,46 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <iostream>
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);
}

View File

@ -6,7 +6,27 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<typename T>
void swap(T &x, T &y)
{
T swap = x;
x = y;
y = swap;
}
template<typename T>
T const &min(T const &x, T const &y)
{
return ((x < y) ? x : y);
}
template<typename T>
T const &max(T const &x, T const &y)
{
return ((x > y) ? x : y);
}