resolve template specialization with inline keyword

This commit is contained in:
hugogogo
2022-06-18 17:58:14 +02:00
parent 72762a79cb
commit 94745ca8a9
11 changed files with 222 additions and 327 deletions

View File

@@ -0,0 +1,76 @@
#include "tests_utils.hpp"
// print vector
// ********************************************
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";
}
// 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] );
}