map pair ok
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
namespace ft = std;
|
||||
#else
|
||||
#include "vector.hpp"
|
||||
#include "map.hpp"
|
||||
#include "reverse_iterator.hpp"
|
||||
#endif
|
||||
|
||||
@@ -82,9 +83,6 @@ extern std::vector< mystruct* > mem_list;
|
||||
{ void func(); };\
|
||||
void f_name () {\
|
||||
add_to_list(#f_name, "int, int", new(s_ ## f_name <int, int>));\
|
||||
add_to_list("", "char, int", new(s_ ## f_name <char, int>));\
|
||||
add_to_list("", "std::string, int", new(s_ ## f_name <std::string, int>));\
|
||||
add_to_list("", "mystruct*, int", new(s_ ## f_name <mystruct*, int>));\
|
||||
}\
|
||||
template <class T, class U>\
|
||||
void s_ ## f_name <T, U>::func()
|
||||
@@ -104,15 +102,15 @@ template <class T>
|
||||
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n";
|
||||
}
|
||||
template <class T, class U>
|
||||
void print(ft::map<T, U> ma) {
|
||||
void print(ft::map<T, U> mp) {
|
||||
|
||||
int i = 0;
|
||||
typename ft::map<T, U>::iterator it;
|
||||
typename ft::map<T, U>::iterator it_end = ma.end();
|
||||
typename ft::map<T, U>::iterator it_end = mp.end();
|
||||
|
||||
for (it = ma.begin(); it != it_end; ++it, i++)
|
||||
for (it = mp.begin(); it != it_end; ++it, i++)
|
||||
std::cout << "[" << i << "]" << it->first << ":" << it->second << " ";
|
||||
std::cout << "\nsize:" << ma.size() << "\n";
|
||||
std::cout << "\nsize:" << mp.size() << "\n";
|
||||
}
|
||||
|
||||
// templates get value
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
int main() {
|
||||
|
||||
// VECTOR
|
||||
tests_vector_constructor();
|
||||
// tests_vector_constructor();
|
||||
// tests_vector_operator_assignation();
|
||||
// tests_vector_begin();
|
||||
// tests_vector_end();
|
||||
@@ -57,6 +57,8 @@ int main() {
|
||||
// tests_map_upper_bound();
|
||||
// tests_map_equal_range();
|
||||
// tests_map_get_allocator();
|
||||
// tests_map_relational_operators();
|
||||
// tests_map_swap_non_member();
|
||||
|
||||
|
||||
// STACK
|
||||
|
||||
@@ -9,15 +9,12 @@ TEST_M(tests_map_simple)
|
||||
// title
|
||||
TITLE(simple test)
|
||||
|
||||
typename std::map<T, U> first;
|
||||
typename std::map<T, U>::iterator it;
|
||||
|
||||
first[VALT('a')]=VALU(10);
|
||||
first[VALT('b')]=VALU(30);
|
||||
first[VALT('c')]=VALU(50);
|
||||
first[VALT('d')]=VALU(70);
|
||||
|
||||
PRINT(first)
|
||||
typename ft::map<T, U> mp;
|
||||
// typename std::map<T, U>::iterator it;
|
||||
//
|
||||
// mp[VALT('a')] = VALU(10);
|
||||
//
|
||||
// PRINT(mp)
|
||||
|
||||
DELETE
|
||||
}
|
||||
@@ -543,6 +540,71 @@ TEST_M(tests_map_get_allocator)
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST_M(tests_map_relational_operators)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<int, char> alice{{1, 'a'}, {2, 'b'}, {3, 'c'}};
|
||||
std::map<int, char> bob{{7, 'Z'}, {8, 'Y'}, {9, 'X'}, {10, 'W'}};
|
||||
std::map<int, char> eve{{1, 'a'}, {2, 'b'}, {3, 'c'}};
|
||||
|
||||
std::cout << std::boolalpha;
|
||||
|
||||
// Compare non equal containers
|
||||
std::cout << "alice == bob returns " << (alice == bob) << '\n';
|
||||
std::cout << "alice != bob returns " << (alice != bob) << '\n';
|
||||
std::cout << "alice < bob returns " << (alice < bob) << '\n';
|
||||
std::cout << "alice <= bob returns " << (alice <= bob) << '\n';
|
||||
std::cout << "alice > bob returns " << (alice > bob) << '\n';
|
||||
std::cout << "alice >= bob returns " << (alice >= bob) << '\n';
|
||||
|
||||
std::cout << '\n';
|
||||
|
||||
// Compare equal containers
|
||||
std::cout << "alice == eve returns " << (alice == eve) << '\n';
|
||||
std::cout << "alice != eve returns " << (alice != eve) << '\n';
|
||||
std::cout << "alice < eve returns " << (alice < eve) << '\n';
|
||||
std::cout << "alice <= eve returns " << (alice <= eve) << '\n';
|
||||
std::cout << "alice > eve returns " << (alice > eve) << '\n';
|
||||
std::cout << "alice >= eve returns " << (alice >= eve) << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
|
||||
TEST_M(tests_map_swap_non_member)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<int, char> alice{{1, 'a'}, {2, 'b'}, {3, 'c'}};
|
||||
std::map<int, char> bob{{7, 'Z'}, {8, 'Y'}, {9, 'X'}, {10, 'W'}};
|
||||
|
||||
auto print = [](std::pair<const int, char>& n) {
|
||||
std::cout << " " << n.first << '(' << n.second << ')';
|
||||
};
|
||||
|
||||
// Print state before swap
|
||||
std::cout << "alice:";
|
||||
std::for_each(alice.begin(), alice.end(), print);
|
||||
std::cout << "\n" "bob :";
|
||||
std::for_each(bob.begin(), bob.end(), print);
|
||||
std::cout << '\n';
|
||||
|
||||
std::cout << "-- SWAP\n";
|
||||
std::swap(alice, bob);
|
||||
|
||||
// Print state after swap
|
||||
std::cout << "alice:";
|
||||
std::for_each(alice.begin(), alice.end(), print);
|
||||
std::cout << "\n" "bob :";
|
||||
std::for_each(bob.begin(), bob.end(), print);
|
||||
std::cout << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user