d08 ex00 ok

This commit is contained in:
hugogogo
2022-03-13 18:33:48 +01:00
parent 96e78e34a1
commit a3be2c8f16
4 changed files with 183 additions and 0 deletions

58
d08/ex00/main.cpp Normal file
View File

@@ -0,0 +1,58 @@
#include <iostream>
#include <string>
#include "colors.h"
#include "easyfind.hpp"
#include <list>
#include <vector>
#include <deque>
#define N_TEST "3"
template < typename T >
void standardTest(T container) {
typename T::const_iterator it;
int test;
for (int i = -9 ; i < 10 ; i++)
container.push_back(i);
for (it = container.begin(); it != container.end(); it++)
std::cout << *it << ": " << &*it << "\n";
std::cout << "\n";
test = -3;
try {
it = easyfind(container, test);
std::cout << *it << ": " << &*it << "\n";
}
catch (std::exception const & e) {
std::cout << test << ": " << e.what() << "\n";
}
}
int main() {
int i = 0;
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "tests list :" RESET "\n";
{
std::list<int> container;
standardTest(container);
}
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "tests vector :" RESET "\n";
{
std::vector<int> container;
standardTest(container);
}
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "tests deque :" RESET "\n";
{
std::deque<int> container;
standardTest(container);
}
return 0;
}