little add

This commit is contained in:
kinou-p 2022-11-29 15:08:15 +01:00
parent 560e1e985c
commit 3d078ae677
2 changed files with 10 additions and 29 deletions

View File

@ -126,13 +126,8 @@ class map
~map() ~map()
{ {
// if (_size && _root && _root != _end)
// this->clear();
//if (_size)
//{
this->destructTree(_root); this->destructTree(_root);
this->destructNode(_end); this->destructNode(_end);
//}
} }
map& operator=(const map& x) map& operator=(const map& x)
@ -141,11 +136,7 @@ class map
_comp = (x._comp); _comp = (x._comp);
_alloc = (x._alloc); _alloc = (x._alloc);
_node_alloc = (x._node_alloc); _node_alloc = (x._node_alloc);
//destructNode(_end);
//_end = x._end;
_size = 0; _size = 0;
//_end = _node_alloc.allocate(1);
//_node_alloc.construct(_end, node());
_root = _end; _root = _end;
insert(x.begin(), x.end()); insert(x.begin(), x.end());
return (*this); return (*this);
@ -333,17 +324,6 @@ class map
void swap (map& x) void swap (map& x)
{ {
//map tmp;
// key_compare _comp;
// allocator_type _alloc;
// node_allocator_type _node_alloc;
// NodePtr _root;
// NodePtr _end;
// size_type _size;
// //destructNode(tmp._end);
key_compare tmp_comp = _comp; key_compare tmp_comp = _comp;
allocator_type tmp_alloc = _alloc; allocator_type tmp_alloc = _alloc;
node_allocator_type tmp_node_alloc = _node_alloc; node_allocator_type tmp_node_alloc = _node_alloc;
@ -358,22 +338,17 @@ class map
_size = x._size; _size = x._size;
_end = x._end; _end = x._end;
//x = tmp;
x._comp = tmp_comp; x._comp = tmp_comp;
x._alloc = tmp_alloc; x._alloc = tmp_alloc;
x._node_alloc = tmp_node_alloc; x._node_alloc = tmp_node_alloc;
x._root = tmp_root; x._root = tmp_root;
x._size = tmp_size; x._size = tmp_size;
x._end = tmp_end; x._end = tmp_end;
//tmp._end = 0;
//tmp._size = 0;
} }
void clear() void clear()
{ {
this->destructTree(_root); this->destructTree(_root);
// this->destructNode(_end);
_size = 0; _size = 0;
_root = _end; _root = _end;
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 12:55:23 by apommier #+# #+# */ /* Created: 2022/11/29 12:55:23 by apommier #+# #+# */
/* Updated: 2022/11/29 14:45:23 by apommier ### ########.fr */ /* Updated: 2022/11/29 15:06:00 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -54,6 +54,10 @@ void vector_tester()
ctnr.assign(10, 1); ctnr.assign(10, 1);
printSize(ctnr); printSize(ctnr);
std::cout << "----copy constructor----" << std::endl;
ft::vector<int> ctnr_copy(ctnr);
printSize(ctnr_copy);
std::cout << "----range constructor----" << std::endl; std::cout << "----range constructor----" << std::endl;
ft::vector<int> ctnr2(ctnr.begin(), ctnr.end()); ft::vector<int> ctnr2(ctnr.begin(), ctnr.end());
printSize(ctnr2); printSize(ctnr2);
@ -156,7 +160,7 @@ void real_vector_tester()
std::vector<int> ctnr3; std::vector<int> ctnr3;
ctnr3.assign(ctnr.begin(), ctnr.end()); ctnr3.assign(ctnr.begin(), ctnr.end());
printSize_real(ctnr3); printSize_real(ctnr3);
////////////
std::cout << "----insert at position + assign constrcutor----" << std::endl; std::cout << "----insert at position + assign constrcutor----" << std::endl;
std::vector<int> ctnr4(5, 5); std::vector<int> ctnr4(5, 5);
printSize_real(ctnr4); printSize_real(ctnr4);
@ -230,4 +234,6 @@ void real_vector_tester()
std::cout << "----relationnal ope----\n"; std::cout << "----relationnal ope----\n";
cmp(ctnr, ctnr4); cmp(ctnr, ctnr4);
} }