all tests except one ok on map
This commit is contained in:
@@ -163,9 +163,10 @@ public:
|
||||
// get_allocator -----------------------------
|
||||
allocator_type get_allocator() const;
|
||||
|
||||
// TMP non privat
|
||||
bst_map _bst;
|
||||
private:
|
||||
|
||||
bst_map _bst;
|
||||
allocator_type _allocator;
|
||||
key_compare _comp;
|
||||
|
||||
|
||||
@@ -238,22 +238,28 @@ MP_TPL typename MP::allocator_type MP::
|
||||
************************/
|
||||
// operator == -------------------------------
|
||||
template< class Key, class T, class Compare, class Alloc > bool operator==
|
||||
( const MP& lhs, const MP& rhs ) { return (lhs._bst == rhs._bst); }
|
||||
// operator != -------------------------------
|
||||
template< class Key, class T, class Compare, class Alloc > bool operator!=
|
||||
( const MP& lhs, const MP& rhs ) { return (lhs._bst != rhs._bst); }
|
||||
( const MP& lhs, const MP& rhs ) {
|
||||
|
||||
return (lhs._bst == rhs._bst);
|
||||
}
|
||||
// operator < --------------------------------
|
||||
template< class Key, class T, class Compare, class Alloc > bool operator<
|
||||
( const MP& lhs, const MP& rhs ) { return (lhs._bst < rhs._bst); }
|
||||
( const MP& lhs, const MP& rhs ) {
|
||||
|
||||
return (lhs._bst < rhs._bst);
|
||||
}
|
||||
// operator != -------------------------------
|
||||
template< class Key, class T, class Compare, class Alloc > bool operator!=
|
||||
( const MP& lhs, const MP& rhs ) { return !(lhs == rhs); }
|
||||
// operator <= -------------------------------
|
||||
template< class Key, class T, class Compare, class Alloc > bool operator<=
|
||||
( const MP& lhs, const MP& rhs ) { return (lhs._bst <= rhs._bst); }
|
||||
( const MP& lhs, const MP& rhs ) { return !(lhs > rhs); }
|
||||
// operator > --------------------------------
|
||||
template< class Key, class T, class Compare, class Alloc > bool operator>
|
||||
( const MP& lhs, const MP& rhs ) { return (lhs._bst > rhs._bst); }
|
||||
( const MP& lhs, const MP& rhs ) { return (rhs < lhs); }
|
||||
// operator >= -------------------------------
|
||||
template< class Key, class T, class Compare, class Alloc > bool operator>=
|
||||
( const MP& lhs, const MP& rhs ) { return (lhs._bst >= rhs._bst); }
|
||||
( const MP& lhs, const MP& rhs ) { return !(lhs < rhs); }
|
||||
// swap (map) -----------------------------
|
||||
template< class Key, class T, class Compare, class Alloc > void swap
|
||||
( const MP& lhs, const MP& rhs ) { lhs.swap(rhs); }
|
||||
|
||||
@@ -69,6 +69,8 @@ void tests_map_lower_bound();
|
||||
void tests_map_upper_bound();
|
||||
void tests_map_equal_range();
|
||||
void tests_map_get_allocator();
|
||||
void tests_map_relational_operators();
|
||||
void tests_map_swap_non_member();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -70,10 +70,11 @@ extern std::vector< mystruct* > mem_list;
|
||||
template <class T> struct s_ ## f_name : public A_test\
|
||||
{ void func(); };\
|
||||
void f_name () {\
|
||||
add_to_list("", "", NULL);\
|
||||
add_to_list(#f_name, "int", new(s_ ## f_name <int>));\
|
||||
add_to_list("", "char", new(s_ ## f_name <char>));\
|
||||
add_to_list("", "std::string", new(s_ ## f_name <std::string>));\
|
||||
add_to_list("", "mystruct*", new(s_ ## f_name <mystruct*>));\
|
||||
add_to_list(#f_name, "char", new(s_ ## f_name <char>));\
|
||||
add_to_list(#f_name, "std::string", new(s_ ## f_name <std::string>));\
|
||||
add_to_list(#f_name, "mystruct*", new(s_ ## f_name <mystruct*>));\
|
||||
}\
|
||||
template <class T>\
|
||||
void s_ ## f_name <T>::func()
|
||||
@@ -82,14 +83,23 @@ extern std::vector< mystruct* > mem_list;
|
||||
template <class T, class U> struct s_ ## f_name : public A_test\
|
||||
{ void func(); };\
|
||||
void f_name () {\
|
||||
add_to_list("", "", NULL);\
|
||||
add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name <char, mystruct*>));\
|
||||
add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name <int, mystruct*>));\
|
||||
}\
|
||||
template <class T, class U>\
|
||||
void s_ ## f_name <T, U>::func()
|
||||
|
||||
/*
|
||||
add_to_list(#f_name, "char, int", new(s_ ## f_name <char, int>));\
|
||||
add_to_list(#f_name, "char, char", new(s_ ## f_name <char, char>));\
|
||||
add_to_list(#f_name, "char, std::string", new(s_ ## f_name <char, std::string>));\
|
||||
add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name <char, mystruct*>));\
|
||||
}\
|
||||
template <class T, class U>\
|
||||
void s_ ## f_name <T, U>::func()
|
||||
|
||||
add_to_list(#f_name, "int, int", new(s_ ## f_name <int, int>));\
|
||||
add_to_list(#f_name, "int, char", new(s_ ## f_name <int, char>));\
|
||||
add_to_list(#f_name, "int, std::string", new(s_ ## f_name <int, std::string>));\
|
||||
add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name <int, mystruct*>));\
|
||||
*/
|
||||
|
||||
// templates print
|
||||
// *****************************************
|
||||
|
||||
@@ -45,20 +45,20 @@ int main() {
|
||||
tests_map_size();
|
||||
tests_map_max_size();
|
||||
tests_map_operator_access();
|
||||
// tests_map_insert();
|
||||
// tests_map_erase();
|
||||
// tests_map_swap();
|
||||
// tests_map_clear();
|
||||
// tests_map_key_comp();
|
||||
// tests_map_value_comp();
|
||||
// tests_map_find();
|
||||
// tests_map_count();
|
||||
// tests_map_lower_bound();
|
||||
// tests_map_upper_bound();
|
||||
// tests_map_equal_range();
|
||||
// tests_map_get_allocator();
|
||||
tests_map_insert();
|
||||
tests_map_erase();
|
||||
tests_map_swap();
|
||||
tests_map_clear();
|
||||
tests_map_key_comp();
|
||||
tests_map_value_comp();
|
||||
tests_map_find();
|
||||
tests_map_count();
|
||||
tests_map_lower_bound();
|
||||
tests_map_upper_bound();
|
||||
tests_map_equal_range();
|
||||
tests_map_get_allocator();
|
||||
// tests_map_relational_operators();
|
||||
// tests_map_swap_non_member();
|
||||
tests_map_swap_non_member();
|
||||
|
||||
|
||||
// STACK
|
||||
|
||||
@@ -10,8 +10,11 @@ void add_to_list(std::string title, std::string type, A_test* test) {
|
||||
std::vector< std::vector<A_test*> >::iterator it;
|
||||
|
||||
// title != NULL for the first element
|
||||
if (!title.empty())
|
||||
if (test == NULL)
|
||||
{
|
||||
test_list.push_back(test_sub_list);
|
||||
return;
|
||||
}
|
||||
|
||||
test->title = title;
|
||||
test->type = type;
|
||||
|
||||
@@ -229,42 +229,36 @@ TEST_M(tests_map_operator_access)
|
||||
DELETE
|
||||
}
|
||||
|
||||
/*
|
||||
TEST_M(tests_map_insert)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
ft::map<T,U> mymap;
|
||||
|
||||
// first insert function version (single parameter):
|
||||
mymap.insert ( std::pair<char,int>('a',100) );
|
||||
mymap.insert ( std::pair<char,int>('z',200) );
|
||||
mymap.insert ( ft::pair<T,U>(VALT('a'),VALU(100)) );
|
||||
mymap.insert ( ft::pair<T,U>(VALT('z'),VALU(200)) );
|
||||
|
||||
std::pair<std::map<char,int>::iterator,bool> ret;
|
||||
ret = mymap.insert ( std::pair<char,int>('z',500) );
|
||||
ft::pair<typename ft::map<T,U>::iterator, bool> ret;
|
||||
ret = mymap.insert ( ft::pair<T,U>(VALT('z'),VALU(500)) );
|
||||
if (ret.second==false) {
|
||||
std::cout << "element 'z' already existed";
|
||||
std::cout << " with a value of " << ret.first->second << '\n';
|
||||
}
|
||||
|
||||
|
||||
// second insert function version (with hint position):
|
||||
std::map<char,int>::iterator it = mymap.begin();
|
||||
mymap.insert (it, std::pair<char,int>('b',300)); // max efficiency inserting
|
||||
mymap.insert (it, std::pair<char,int>('c',400)); // no max efficiency inserting
|
||||
typename ft::map<T,U>::iterator it = mymap.begin();
|
||||
mymap.insert (it, ft::pair<T,U>(VALT('b'),VALU(300))); // max efficiency inserting
|
||||
mymap.insert (it, ft::pair<T,U>(VALT('c'),VALU(400))); // no max efficiency inserting
|
||||
|
||||
// third insert function version (range insertion):
|
||||
std::map<char,int> anothermap;
|
||||
ft::map<T,U> anothermap;
|
||||
anothermap.insert(mymap.begin(),mymap.find('c'));
|
||||
|
||||
// showing contents:
|
||||
std::cout << "mymap contains:\n";
|
||||
for (it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
std::cout << "anothermap contains:\n";
|
||||
for (it=anothermap.begin(); it!=anothermap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
PRINT(mymap)
|
||||
PRINT(anothermap)
|
||||
|
||||
DELETE
|
||||
}
|
||||
@@ -274,28 +268,26 @@ TEST_M(tests_map_erase)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
std::map<char,int>::iterator it;
|
||||
ft::map<T,U> mymap;
|
||||
typename ft::map<T,U>::iterator it;
|
||||
|
||||
// insert some values:
|
||||
mymap['a']=10;
|
||||
mymap['b']=20;
|
||||
mymap['c']=30;
|
||||
mymap['d']=40;
|
||||
mymap['e']=50;
|
||||
mymap['f']=60;
|
||||
mymap[VALT('a')]=VALU(10);
|
||||
mymap[VALT('b')]=VALU(20);
|
||||
mymap[VALT('c')]=VALU(30);
|
||||
mymap[VALT('d')]=VALU(40);
|
||||
mymap[VALT('e')]=VALU(50);
|
||||
mymap[VALT('f')]=VALU(60);
|
||||
|
||||
it=mymap.find('b');
|
||||
mymap.erase (it); // erasing by iterator
|
||||
it=mymap.find(VALT('b'));
|
||||
mymap.erase (it); // erasing by iterator
|
||||
|
||||
mymap.erase ('c'); // erasing by key
|
||||
mymap.erase (VALT('c')); // erasing by key
|
||||
|
||||
it=mymap.find ('e');
|
||||
mymap.erase ( it, mymap.end() ); // erasing by range
|
||||
it=mymap.find (VALT('e'));
|
||||
mymap.erase ( it, mymap.end() ); // erasing by range
|
||||
|
||||
// show content:
|
||||
for (it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
PRINT(mymap)
|
||||
|
||||
DELETE
|
||||
}
|
||||
@@ -305,24 +297,19 @@ TEST_M(tests_map_swap)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> foo,bar;
|
||||
ft::map<T,U> foo,bar;
|
||||
|
||||
foo['x']=100;
|
||||
foo['y']=200;
|
||||
foo[VALT('x')]=VALU(100);
|
||||
foo[VALT('y')]=VALU(200);
|
||||
|
||||
bar['a']=11;
|
||||
bar['b']=22;
|
||||
bar['c']=33;
|
||||
bar[VALT('a')]=VALU(11);
|
||||
bar[VALT('b')]=VALU(22);
|
||||
bar[VALT('c')]=VALU(33);
|
||||
|
||||
foo.swap(bar);
|
||||
|
||||
std::cout << "foo contains:\n";
|
||||
for (std::map<char,int>::iterator it=foo.begin(); it!=foo.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
std::cout << "bar contains:\n";
|
||||
for (std::map<char,int>::iterator it=bar.begin(); it!=bar.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
PRINT(foo)
|
||||
PRINT(bar)
|
||||
|
||||
DELETE
|
||||
}
|
||||
@@ -332,23 +319,19 @@ TEST_M(tests_map_clear)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
ft::map<T,U> mymap;
|
||||
|
||||
mymap['x']=100;
|
||||
mymap['y']=200;
|
||||
mymap['z']=300;
|
||||
mymap[VALT('x')]=VALU(100);
|
||||
mymap[VALT('y')]=VALU(200);
|
||||
mymap[VALT('z')]=VALU(300);
|
||||
|
||||
std::cout << "mymap contains:\n";
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
PRINT(mymap)
|
||||
|
||||
mymap.clear();
|
||||
mymap['a']=1101;
|
||||
mymap['b']=2202;
|
||||
mymap[VALT('a')]=VALU(1101);
|
||||
mymap[VALT('b')]=VALU(2202);
|
||||
|
||||
std::cout << "mymap contains:\n";
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
PRINT(mymap)
|
||||
|
||||
DELETE
|
||||
}
|
||||
@@ -358,19 +341,19 @@ TEST_M(tests_map_key_comp)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
ft::map<T,U> mymap;
|
||||
|
||||
std::map<char,int>::key_compare mycomp = mymap.key_comp();
|
||||
typename ft::map<T,U>::key_compare mycomp = mymap.key_comp();
|
||||
|
||||
mymap['a']=100;
|
||||
mymap['b']=200;
|
||||
mymap['c']=300;
|
||||
mymap[VALT('a')]=VALU(100);
|
||||
mymap[VALT('b')]=VALU(200);
|
||||
mymap[VALT('c')]=VALU(300);
|
||||
|
||||
std::cout << "mymap contains:\n";
|
||||
|
||||
char highest = mymap.rbegin()->first; // key value of last element
|
||||
T highest = mymap.rbegin()->first; // key value of last element
|
||||
|
||||
std::map<char,int>::iterator it = mymap.begin();
|
||||
typename ft::map<T,U>::iterator it = mymap.begin();
|
||||
do {
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
} while ( mycomp((*it++).first, highest) );
|
||||
@@ -385,17 +368,17 @@ TEST_M(tests_map_value_comp)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
ft::map<T,U> mymap;
|
||||
|
||||
mymap['x']=1001;
|
||||
mymap['y']=2002;
|
||||
mymap['z']=3003;
|
||||
mymap[VALT('x')]=VALU(1001);
|
||||
mymap[VALT('y')]=VALU(2002);
|
||||
mymap[VALT('z')]=VALU(3003);
|
||||
|
||||
std::cout << "mymap contains:\n";
|
||||
|
||||
std::pair<char,int> highest = *mymap.rbegin(); // last element
|
||||
ft::pair<T,U> highest = *mymap.rbegin(); // last element
|
||||
|
||||
std::map<char,int>::iterator it = mymap.begin();
|
||||
typename ft::map<T,U>::iterator it = mymap.begin();
|
||||
do {
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
} while ( mymap.value_comp()(*it++, highest) );
|
||||
@@ -408,23 +391,23 @@ TEST_M(tests_map_find)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
std::map<char,int>::iterator it;
|
||||
ft::map<T,U> mymap;
|
||||
typename ft::map<T,U>::iterator it;
|
||||
|
||||
mymap['a']=50;
|
||||
mymap['b']=100;
|
||||
mymap['c']=150;
|
||||
mymap['d']=200;
|
||||
mymap[VALT('a')]=VALU(50);
|
||||
mymap[VALT('b')]=VALU(100);
|
||||
mymap[VALT('c')]=VALU(150);
|
||||
mymap[VALT('d')]=VALU(200);
|
||||
|
||||
it = mymap.find('b');
|
||||
it = mymap.find(VALT('b'));
|
||||
if (it != mymap.end())
|
||||
mymap.erase (it);
|
||||
|
||||
// print content:
|
||||
std::cout << "elements in mymap:" << '\n';
|
||||
std::cout << "a => " << mymap.find('a')->second << '\n';
|
||||
std::cout << "c => " << mymap.find('c')->second << '\n';
|
||||
std::cout << "d => " << mymap.find('d')->second << '\n';
|
||||
std::cout << "a => " << mymap.find(VALT('a'))->second << '\n';
|
||||
std::cout << "c => " << mymap.find(VALT('c'))->second << '\n';
|
||||
std::cout << "d => " << mymap.find(VALT('d'))->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
@@ -434,14 +417,15 @@ TEST_M(tests_map_count)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
char c;
|
||||
ft::map<T,U> mymap;
|
||||
T c;
|
||||
|
||||
mymap ['a']=101;
|
||||
mymap ['c']=202;
|
||||
mymap ['f']=303;
|
||||
mymap [VALT('a')]=VALU(101);
|
||||
mymap [VALT('c')]=VALU(202);
|
||||
mymap [VALT('f')]=VALU(303);
|
||||
|
||||
for (c='a'; c<'h'; c++)
|
||||
// to do this test with T as a 'string' or 'mystruct*' we should add overload
|
||||
for (c=VALT('a'); c<VALT('h'); c++)
|
||||
{
|
||||
std::cout << c;
|
||||
if (mymap.count(c)>0)
|
||||
@@ -458,23 +442,21 @@ TEST_M(tests_map_lower_bound)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
std::map<char,int>::iterator itlow,itup;
|
||||
ft::map<T,U> mymap;
|
||||
typename ft::map<T,U>::iterator itlow,itup;
|
||||
|
||||
mymap['a']=20;
|
||||
mymap['b']=40;
|
||||
mymap['c']=60;
|
||||
mymap['d']=80;
|
||||
mymap['e']=100;
|
||||
mymap[VALT('a')]=VALU(20);
|
||||
mymap[VALT('b')]=VALU(40);
|
||||
mymap[VALT('c')]=VALU(60);
|
||||
mymap[VALT('d')]=VALU(80);
|
||||
mymap[VALT('e')]=VALU(100);
|
||||
|
||||
itlow=mymap.lower_bound ('b'); // itlow points to b
|
||||
itup=mymap.upper_bound ('d'); // itup points to e (not d!)
|
||||
itlow=mymap.lower_bound (VALT('b')); // itlow points to b
|
||||
itup=mymap.upper_bound (VALT('d')); // itup points to e (not d!)
|
||||
|
||||
mymap.erase(itlow,itup); // erases [itlow,itup)
|
||||
|
||||
// print content:
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
PRINT(mymap)
|
||||
|
||||
DELETE
|
||||
}
|
||||
@@ -484,23 +466,21 @@ TEST_M(tests_map_upper_bound)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
std::map<char,int>::iterator itlow,itup;
|
||||
ft::map<T,U> mymap;
|
||||
typename ft::map<T,U>::iterator itlow,itup;
|
||||
|
||||
mymap['a']=20;
|
||||
mymap['b']=40;
|
||||
mymap['c']=60;
|
||||
mymap['d']=80;
|
||||
mymap['e']=100;
|
||||
mymap[VALT('a')]=VALU(20);
|
||||
mymap[VALT('b')]=VALU(40);
|
||||
mymap[VALT('c')]=VALU(60);
|
||||
mymap[VALT('d')]=VALU(80);
|
||||
mymap[VALT('e')]=VALU(100);
|
||||
|
||||
itlow=mymap.lower_bound ('b'); // itlow points to b
|
||||
itup=mymap.upper_bound ('d'); // itup points to e (not d!)
|
||||
itlow=mymap.lower_bound (VALT('b')); // itlow points to b
|
||||
itup=mymap.upper_bound (VALT('d')); // itup points to e (not d!)
|
||||
|
||||
mymap.erase(itlow,itup); // erases [itlow,itup)
|
||||
mymap.erase(itlow,itup); // erases [itlow,itup)
|
||||
|
||||
// print content:
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
PRINT(mymap)
|
||||
|
||||
DELETE
|
||||
}
|
||||
@@ -510,14 +490,14 @@ TEST_M(tests_map_equal_range)
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
ft::map<T,U> mymap;
|
||||
|
||||
mymap['a']=10;
|
||||
mymap['b']=20;
|
||||
mymap['c']=30;
|
||||
mymap[VALT('a')]=VALU(10);
|
||||
mymap[VALT('b')]=VALU(20);
|
||||
mymap[VALT('c')]=VALU(30);
|
||||
|
||||
std::pair<std::map<char,int>::iterator,std::map<char,int>::iterator> ret;
|
||||
ret = mymap.equal_range('b');
|
||||
ft::pair<typename ft::map<T,U>::iterator,typename ft::map<T,U>::iterator> ret;
|
||||
ret = mymap.equal_range(VALT('b'));
|
||||
|
||||
std::cout << "lower bound points to: ";
|
||||
std::cout << ret.first->first << " => " << ret.first->second << '\n';
|
||||
@@ -534,14 +514,14 @@ TEST_M(tests_map_get_allocator)
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
int psize;
|
||||
std::map<char,int> mymap;
|
||||
std::pair<const char,int>* p;
|
||||
ft::map<T,U> mymap;
|
||||
ft::pair<const T,U>* p;
|
||||
|
||||
// allocate an array of 5 elements using mymap's allocator:
|
||||
p=mymap.get_allocator().allocate(5);
|
||||
|
||||
// assign some values to array
|
||||
psize = sizeof(std::map<char,int>::value_type)*5;
|
||||
psize = sizeof(typename ft::map<T,U>::value_type)*5;
|
||||
|
||||
std::cout << "The allocated array has a size of " << psize << " bytes.\n";
|
||||
|
||||
@@ -555,29 +535,45 @@ 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';
|
||||
ft::map<T,U> alice;
|
||||
ft::map<T,U> bob;
|
||||
ft::map<T,U> eve;
|
||||
(void)alice;
|
||||
(void)bob;
|
||||
(void)eve;
|
||||
|
||||
alice[VALT(1)]=VALU('a');
|
||||
alice[VALT(2)]=VALU('b');
|
||||
alice[VALT(3)]=VALU('c');
|
||||
|
||||
bob[VALT(7)]=VALU('Z');
|
||||
bob[VALT(8)]=VALU('Y');
|
||||
bob[VALT(9)]=VALU('X');
|
||||
bob[VALT(10)]=VALU('W');
|
||||
|
||||
eve[VALT(1)]=VALU('a');
|
||||
eve[VALT(2)]=VALU('b');
|
||||
eve[VALT(3)]=VALU('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
|
||||
}
|
||||
@@ -588,33 +584,31 @@ 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';
|
||||
ft::map<T, U> alice;
|
||||
ft::map<T, U> bob;
|
||||
|
||||
alice[VALT(1)]=VALU('a');
|
||||
alice[VALT(2)]=VALU('b');
|
||||
alice[VALT(3)]=VALU('c');
|
||||
|
||||
bob[VALT(7)]=VALU('Z');
|
||||
bob[VALT(8)]=VALU('Y');
|
||||
bob[VALT(9)]=VALU('X');
|
||||
bob[VALT(10)]=VALU('W');
|
||||
|
||||
// Print state before swap
|
||||
PRINT(alice)
|
||||
PRINT(bob)
|
||||
|
||||
std::cout << "-- SWAP\n";
|
||||
std::swap(alice, bob);
|
||||
|
||||
// Print state after swap
|
||||
PRINT(alice)
|
||||
PRINT(bob)
|
||||
|
||||
DELETE
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user