wip added all prototypes of members of vector

This commit is contained in:
hugogogo
2022-06-01 20:20:05 +02:00
parent 99f67b808c
commit f765779b27
2 changed files with 111 additions and 20 deletions

View File

@@ -1,14 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ftvector.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/01 15:39:26 by simplonco #+# #+# */
/* Updated: 2022/06/01 15:39:57 by simplonco ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftvector.hpp"
@@ -18,8 +7,9 @@
* CONSTRUCTORS
*********************************************/
ftvector::ftvector() :
_size(0) {
ftvector::ftvector()
: _size(0)
, _space(0) {
// std::cout << COPLIEN_COLOR "ftvector constructor" RESET "\n";
_allocator = std::allocator<int>();
return;
@@ -70,9 +60,35 @@ unsigned int ftvector::size() const {return _size;}
*********************************************/
void ftvector::push_back(const int & element) {
_mem_ptr = _allocator.allocate(1);
_allocator.construct(_mem_ptr, element);
if (_size == _space)
hold_space(1);
_allocator.construct(&_mem_ptr[_size], element);
_size++;
for (unsigned int i = 0; i < _size; i++)
std::cout << _mem_ptr[i] << "\n";
std::cout << "\n";
}
/*********************************************
* PRIVATE MEMBER FUNCTIONS
*********************************************/
void hold_space(std::size_t add_space) {
if (add_space == 0)
return ;
int * tmp_ptr;
if (_space > 0 && add_space == 1)
{
add_space = _space * 2;
}
tmp_ptr = _allocator.allocate(add_space);
// _mem_ptr = _allocator.allocate(add_space);
}
/*********************************************