resolve template specialization with inline keyword
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
#ifndef A_TEST_HPP
|
||||
# define A_TEST_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
struct A_test
|
||||
{
|
||||
virtual ~A_test(){};
|
||||
std::string title;
|
||||
std::string type;
|
||||
virtual void func() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
#ifndef TESTS_HPP
|
||||
# define TESTS_HPP
|
||||
|
||||
#include "colors.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iomanip> // std::setw()
|
||||
#include <iterator> // std::reverse_iterator
|
||||
#include <utility> // std::make_pair
|
||||
#include <sstream> // std::stringstream
|
||||
|
||||
|
||||
|
||||
// toogle between test ft and stl
|
||||
// *************************
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#ifdef STL
|
||||
namespace ft = std;
|
||||
#else
|
||||
#include "vector.hpp"
|
||||
#include "reverse_iterator.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
// global variables
|
||||
// ***************************************
|
||||
std::vector< std::vector<A_test*> > test_list;
|
||||
std::vector<mystruct*> mem_list;
|
||||
|
||||
|
||||
|
||||
// global functions
|
||||
// ***************************************
|
||||
void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4);
|
||||
|
||||
|
||||
// struct for tests
|
||||
// ***************************************
|
||||
struct mystruct {
|
||||
public:
|
||||
mystruct(int data = 0);
|
||||
~mystruct();
|
||||
int * get_data() const;
|
||||
private:
|
||||
int * _val;
|
||||
};
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const * rhs);
|
||||
|
||||
|
||||
// adding each test to the list
|
||||
// ***************************
|
||||
#define TEST(f_name) \
|
||||
template <class T> struct s_ ## f_name : public A_test\
|
||||
{ void func(); };\
|
||||
void f_name ()\
|
||||
{ add_to_list(\
|
||||
#f_name,\
|
||||
new(s_ ## f_name <int>),\
|
||||
new(s_ ## f_name <char>),\
|
||||
new(s_ ## f_name <std::string>),\
|
||||
new(s_ ## f_name <mystruct*>)\
|
||||
);}\
|
||||
template <class T>\
|
||||
void s_ ## f_name <T>::func()
|
||||
|
||||
|
||||
// defines
|
||||
// ****************************************
|
||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||
# define VAL(n) val<T>(n)
|
||||
# define TOI(n) toi<T>(n)
|
||||
# define PRINT(n) print_vector<T>(n);
|
||||
# define DELETE delete_structs();
|
||||
|
||||
|
||||
// prototypes
|
||||
// *********************************************
|
||||
// vectors
|
||||
void tests_vector_constructor();
|
||||
void tests_vector_operator_assignation();
|
||||
void tests_vector_begin();
|
||||
void tests_vector_end();
|
||||
void tests_vector_rbegin();
|
||||
void tests_vector_rend();
|
||||
void tests_vector_size();
|
||||
void tests_vector_max_size();
|
||||
void tests_vector_resize();
|
||||
void tests_vector_capacity();
|
||||
void tests_vector_empty();
|
||||
void tests_vector_reserve();
|
||||
void tests_vector_operator_access();
|
||||
void tests_vector_at();
|
||||
void tests_vector_front();
|
||||
void tests_vector_back();
|
||||
void tests_vector_assign();
|
||||
void tests_vector_push_back();
|
||||
void tests_vector_pop_back();
|
||||
void tests_vector_insert();
|
||||
void tests_vector_erase();
|
||||
void tests_vector_swap();
|
||||
void tests_vector_clear();
|
||||
void tests_vector_get_allocator();
|
||||
void tests_vector_relational_operators();
|
||||
void tests_vector_swap_non_member();
|
||||
void tests_vector_reverse_iterators();
|
||||
// map
|
||||
void tests_map_simple();
|
||||
//void tests_map_constructor();
|
||||
//void tests_map_operator_assignation();
|
||||
//void tests_map_begin();
|
||||
//void tests_map_end();
|
||||
//void tests_map_rbegin();
|
||||
//void tests_map_rend();
|
||||
//void tests_map_empty();
|
||||
//void tests_map_size();
|
||||
//void tests_map_max_size();
|
||||
//void tests_map_operator_access();
|
||||
//void tests_map_insert();
|
||||
//void tests_map_erase();
|
||||
//void tests_map_swap();
|
||||
//void tests_map_clear();
|
||||
//void tests_map_key_comp();
|
||||
//void tests_map_value_comp();
|
||||
//void tests_map_find();
|
||||
//void tests_map_count();
|
||||
//void tests_map_lower_bound();
|
||||
//void tests_map_upper_bound();
|
||||
//void tests_map_equal_range();
|
||||
//void tests_map_get_allocator();
|
||||
#endif
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
#ifndef TESTS_PROTO_HPP
|
||||
# define TESTS_PROTO_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "A_test.hpp"
|
||||
|
||||
// ************************************
|
||||
// global declarations
|
||||
std::vector< std::vector<A_test*> > test_list;
|
||||
void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4) {
|
||||
|
||||
std::vector<A_test*> test_sub_list;
|
||||
|
||||
s1->title = s;
|
||||
s2->title = s;
|
||||
s3->title = s;
|
||||
s4->title = s;
|
||||
s1->type = "int";
|
||||
s2->type = "char";
|
||||
s3->type = "std::string";
|
||||
s4->type = "mystruct";
|
||||
test_sub_list.push_back(s1);
|
||||
test_sub_list.push_back(s2);
|
||||
test_sub_list.push_back(s3);
|
||||
test_sub_list.push_back(s4);
|
||||
test_list.push_back(test_sub_list);
|
||||
}
|
||||
|
||||
|
||||
// **************************************
|
||||
// prototypes vector
|
||||
void tests_vector_constructor();
|
||||
void tests_vector_operator_assignation();
|
||||
void tests_vector_begin();
|
||||
void tests_vector_end();
|
||||
void tests_vector_rbegin();
|
||||
void tests_vector_rend();
|
||||
void tests_vector_size();
|
||||
void tests_vector_max_size();
|
||||
void tests_vector_resize();
|
||||
void tests_vector_capacity();
|
||||
void tests_vector_empty();
|
||||
void tests_vector_reserve();
|
||||
void tests_vector_operator_access();
|
||||
void tests_vector_at();
|
||||
void tests_vector_front();
|
||||
void tests_vector_back();
|
||||
void tests_vector_assign();
|
||||
void tests_vector_push_back();
|
||||
void tests_vector_pop_back();
|
||||
void tests_vector_insert();
|
||||
void tests_vector_erase();
|
||||
void tests_vector_swap();
|
||||
void tests_vector_clear();
|
||||
void tests_vector_get_allocator();
|
||||
void tests_vector_relational_operators();
|
||||
void tests_vector_swap_non_member();
|
||||
void tests_vector_reverse_iterators();
|
||||
|
||||
|
||||
// *****************************************
|
||||
// prototypes map
|
||||
void tests_map_simple();
|
||||
//void tests_map_constructor();
|
||||
//void tests_map_operator_assignation();
|
||||
//void tests_map_begin();
|
||||
//void tests_map_end();
|
||||
//void tests_map_rbegin();
|
||||
//void tests_map_rend();
|
||||
//void tests_map_empty();
|
||||
//void tests_map_size();
|
||||
//void tests_map_max_size();
|
||||
//void tests_map_operator_access();
|
||||
//void tests_map_insert();
|
||||
//void tests_map_erase();
|
||||
//void tests_map_swap();
|
||||
//void tests_map_clear();
|
||||
//void tests_map_key_comp();
|
||||
//void tests_map_value_comp();
|
||||
//void tests_map_find();
|
||||
//void tests_map_count();
|
||||
//void tests_map_lower_bound();
|
||||
//void tests_map_upper_bound();
|
||||
//void tests_map_equal_range();
|
||||
//void tests_map_get_allocator();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
#ifndef TESTS_UTILS_HPP
|
||||
# define TESTS_UTILS_HPP
|
||||
|
||||
#include "colors.h"
|
||||
#include "A_test.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iomanip> // std::setw()
|
||||
#include <iterator> // std::reverse_iterator
|
||||
#include <utility> // std::make_pair
|
||||
#include <map> // std::map
|
||||
#include <sstream> // std::stringstream
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
// toogle between test ft and stl
|
||||
// *************************
|
||||
#ifdef STL
|
||||
namespace ft = std;
|
||||
#else
|
||||
#include "vector.hpp"
|
||||
#include "reverse_iterator.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
// struct for tests
|
||||
// ***************************************
|
||||
struct mystruct {
|
||||
public:
|
||||
mystruct(int data = 0) {_val = new int[2]; _val[0] = data; _val[1] = data;}
|
||||
~mystruct() {delete[] _val;}
|
||||
int * get_data() const {return _val;}
|
||||
private:
|
||||
int * _val;
|
||||
};
|
||||
//extern std::ostream & operator<<(std::ostream & o, mystruct const & rhs);
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const * rhs) {
|
||||
if (rhs != NULL)
|
||||
o << (*rhs).get_data()[0] << "," << (*rhs).get_data()[1];
|
||||
else
|
||||
o << "NULL";
|
||||
return (o);
|
||||
}
|
||||
|
||||
|
||||
// global declarations
|
||||
// ************************************
|
||||
extern std::vector<A_test*> test_list;
|
||||
extern void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4);
|
||||
std::vector<mystruct*> mem_list;
|
||||
|
||||
|
||||
// adding each test to the list
|
||||
// ***************************
|
||||
#define TEST(f_name) \
|
||||
template <class T> struct s_ ## f_name : public A_test\
|
||||
{ void func(); };\
|
||||
void f_name ()\
|
||||
{ add_to_list(\
|
||||
#f_name,\
|
||||
new(s_ ## f_name <int>),\
|
||||
new(s_ ## f_name <char>),\
|
||||
new(s_ ## f_name <std::string>),\
|
||||
new(s_ ## f_name <mystruct*>)\
|
||||
);}\
|
||||
template <class T>\
|
||||
void s_ ## f_name <T>::func()
|
||||
|
||||
|
||||
// defines
|
||||
// ****************************************
|
||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||
# define VAL(n) val<T>(n)
|
||||
# define TOI(n) toi<T>(n)
|
||||
# define PRINT(n) print_vector<T>(n);
|
||||
# define DELETE delete_structs();
|
||||
|
||||
|
||||
// get a value
|
||||
// *********************************************
|
||||
template <class T>
|
||||
T val(int n) {(void)n; return (T());
|
||||
}
|
||||
template <>
|
||||
int val(int n) {return (n);
|
||||
}
|
||||
template <>
|
||||
char val(int n) {return (n % 94 + 33);
|
||||
}
|
||||
template <>
|
||||
std::string val(int n) {
|
||||
|
||||
std::string str;
|
||||
std::stringstream stream;
|
||||
|
||||
stream << n;
|
||||
stream >> str;
|
||||
stream.clear();
|
||||
return (str);
|
||||
}
|
||||
template <>
|
||||
mystruct* val(int n) {
|
||||
|
||||
mystruct *s = new mystruct(n);
|
||||
mem_list.push_back(s);
|
||||
return ( s );
|
||||
}
|
||||
|
||||
|
||||
// convert a value
|
||||
// *****************************************
|
||||
template <class T>
|
||||
int toi(T t) {(void)t; return (0);
|
||||
}
|
||||
template <>
|
||||
int toi(int i) {return (i);
|
||||
}
|
||||
template <>
|
||||
int toi(char c) {return (c);
|
||||
}
|
||||
template <>
|
||||
int toi(std::string str) {
|
||||
|
||||
int i;
|
||||
std::stringstream stream;
|
||||
|
||||
stream << str;
|
||||
stream >> i;
|
||||
stream.clear();
|
||||
return (i);
|
||||
}
|
||||
template <>
|
||||
int toi(mystruct* s) {
|
||||
|
||||
return ( s->get_data()[0] );
|
||||
}
|
||||
|
||||
|
||||
// get a value
|
||||
// *********************************************
|
||||
template <class T>
|
||||
void print_vector(ft::vector<T> vec) {
|
||||
|
||||
int i = 0;
|
||||
typename ft::vector<T>::iterator it;
|
||||
typename ft::vector<T>::iterator it_end = vec.end();
|
||||
|
||||
for (it = vec.begin(); it != it_end; ++it, i++)
|
||||
std::cout << "[" << i << "]" << *it << " ";
|
||||
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n";
|
||||
}
|
||||
|
||||
|
||||
// delete vector elements
|
||||
// **********************************
|
||||
void delete_structs() {
|
||||
|
||||
std::vector<mystruct*>::iterator it;
|
||||
std::vector<mystruct*>::iterator it_end = mem_list.end();
|
||||
|
||||
for (it = mem_list.begin(); it != it_end; ++it)
|
||||
delete *it;
|
||||
mem_list.clear();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user