nicolas-arnaud
2 years ago
11 changed files with 216 additions and 94 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,14 @@ |
|||
* |
|||
|
|||
!README.md |
|||
!LICENCE |
|||
!.gitignore |
|||
!.clang-format |
|||
!compile_commands.json |
|||
!Session.vim |
|||
|
|||
!includes/ |
|||
!includes/*.hpp |
|||
|
|||
!Makefile |
|||
!tester.cpp |
@ -0,0 +1,40 @@ |
|||
#pragma once |
|||
|
|||
namespace ft { |
|||
// is_integral:
|
|||
template < class T, T val > struct integral_constant { |
|||
typedef integral_constant< T, val > type; |
|||
typedef T value_type; |
|||
static const T value = val; |
|||
operator T() const; |
|||
}; |
|||
|
|||
typedef integral_constant< bool, true > true_type; |
|||
typedef integral_constant< bool, false > false_type; |
|||
|
|||
template < class T > struct is_integral : public false_type {}; |
|||
template < class T > struct is_integral< const T > : public false_type {}; |
|||
|
|||
template <> struct is_integral< bool > : public true_type {}; |
|||
template <> struct is_integral< double > : public true_type {}; |
|||
|
|||
template <> struct is_integral< char > : public true_type {}; |
|||
template <> struct is_integral< short > : public true_type {}; |
|||
template <> struct is_integral< int > : public true_type {}; |
|||
template <> struct is_integral< long > : public true_type {}; |
|||
template <> struct is_integral< long long > : public true_type {}; |
|||
|
|||
template <> struct is_integral< unsigned char > : public true_type {}; |
|||
template <> struct is_integral< unsigned short > : public true_type {}; |
|||
template <> struct is_integral< unsigned int > : public true_type {}; |
|||
template <> struct is_integral< unsigned long > : public true_type {}; |
|||
template <> struct is_integral< unsigned long long > : public true_type {}; |
|||
|
|||
// enable_if:
|
|||
template < bool B, class T = void > struct enable_if {}; |
|||
|
|||
template < class T > struct enable_if< true, T > { |
|||
typedef T type; |
|||
}; |
|||
|
|||
} // namespace ft
|
@ -1,16 +1,72 @@ |
|||
#include "ft_container.hpp" |
|||
|
|||
int main(void) { |
|||
ft::vector<int> test1 = ft::vector<int>(); |
|||
ft::vector<int> test2 = ft::vector<int>(10); |
|||
ft::vector<int> test3 = ft::vector<int>(10, 4); |
|||
ft::vector<int> test4 = ft::vector<int>(test3.begin(), test3.begin() + 4); |
|||
ft::vector<int> test5 = ft::vector<int>(test3); |
|||
|
|||
debug_vector(test1); |
|||
debug_vector(test2); |
|||
debug_vector(test3); |
|||
debug_vector(test4); |
|||
debug_vector(test5); |
|||
// debugs:
|
|||
//
|
|||
|
|||
void test_vectors(void) { |
|||
|
|||
ft::vector< int > test1 = ft::vector< int >(); |
|||
ft::vector< int > test2 = ft::vector< int >(10); |
|||
ft::vector< int > test3 = ft::vector< int >(10, 4); |
|||
ft::vector< int > test4 = ft::vector< int >(test3.begin(), test3.begin() + 4); |
|||
ft::vector< int > test5 = ft::vector< int >(test3); |
|||
|
|||
std::cout << "1) vector<int>() | "; |
|||
test1.print(); |
|||
std::cout << "2) vector<int>(10) | "; |
|||
test2.print(); |
|||
std::cout << "3) vector<int>(10, 4) | "; |
|||
test3.print(); |
|||
std::cout << "4) vector<int>(test3.begin(), test3.begin() + 4) | "; |
|||
test4.print(); |
|||
std::cout << "5.a) vector<int>(test3) | "; |
|||
test5.print(); |
|||
|
|||
ft::vector< int >::reference test5_begin = *test5.begin(); |
|||
std::cout << "5.b) test5_begin = *test5.begin() | " << test5_begin |
|||
<< std::endl; |
|||
test5 = test4; |
|||
std::cout << "\ttest5 = test4 | "; |
|||
test5.print(); |
|||
std::cout << "\ttest5_begin | " << test5_begin << std::endl; |
|||
|
|||
std::cout << "6.a) test5.assign(2,2) | "; |
|||
test5.assign(2, 2); |
|||
test5.print(); |
|||
|
|||
std::cout << "6.b) test5.assign(test3.begin(), test3.begin() + 4) | "; |
|||
test5.assign(test3.begin(), test3.begin() + 4); |
|||
test5.print(); |
|||
std::cout << "7.a) test5.at(0) | " << test5.at(0) << std::endl; |
|||
std::cout << "7.b) test5.at(4) | " << test5.at(4) << std::endl; |
|||
std::cout << "7.c) test5.at(5) | "; |
|||
try { |
|||
std::cout << test5.at(5) << std::endl; |
|||
} catch (std::exception &e) { |
|||
std::cout << e.what() << std::endl; |
|||
} |
|||
std::cout << "8.a) test5[4] = 1; | " << (test5[4] = 1) << std::endl; |
|||
std::cout << "8.b) test5[0] | " << test5[0] << std::endl; |
|||
std::cout << "8.c) test5[4] | " << test5[4] << std::endl; |
|||
std::cout << "9.a) test5.front() | " << test5.front() << std::endl; |
|||
std::cout << "9.b) test5.back() | " << test5.back() << std::endl; |
|||
std::cout << "10.a) *test5.data() | " << *test5.data() << std::endl; |
|||
|
|||
|
|||
std::cout << "11.a) test5.empty() | " << test5.empty() << std::endl; |
|||
std::cout << "11.b) test5.size() | " << test5.size() << std::endl; |
|||
std::cout << "11.c) test5.max_size() | " << test5.max_size() << std::endl; |
|||
std::cout << "11.d) test5.capacity() | " << test5.capacity() << std::endl; |
|||
|
|||
test5.resize(0); |
|||
std::cout << "12.a) test5.resize(0) : "<< std::endl; |
|||
std::cout << "12.b) test5.empty() | " << test5.empty() << std::endl; |
|||
std::cout << "12.c) test5.size() | " << test5.size() << std::endl; |
|||
std::cout << "12.d) test5.max_size() | " << test5.max_size() << std::endl; |
|||
std::cout << "12.e) test5.capacity() | " << test5.capacity() << std::endl; |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
int main(void) { test_vectors(); } |
|||
|
Loading…
Reference in new issue