wip added all prototypes of members of vector
This commit is contained in:
@@ -15,17 +15,92 @@ public:
|
|||||||
~ftvector();
|
~ftvector();
|
||||||
ftvector & operator=( ftvector const & rhs );
|
ftvector & operator=( ftvector const & rhs );
|
||||||
|
|
||||||
|
|
||||||
|
/*************
|
||||||
|
* iterators :
|
||||||
|
*************/
|
||||||
|
// begin
|
||||||
|
// iterator begin();
|
||||||
|
// const_iterator begin() const;
|
||||||
|
// end
|
||||||
|
// iterator end();
|
||||||
|
// const_iterator end() const;
|
||||||
|
// rbegin
|
||||||
|
// reverse_iterator rbegin();
|
||||||
|
// const_reverse_iterator rbegin() const;
|
||||||
|
// rend
|
||||||
|
// reverse_iterator rend();
|
||||||
|
// const_reverse_iterator rend() const;
|
||||||
|
|
||||||
|
/************
|
||||||
|
* capacity :
|
||||||
|
************/
|
||||||
|
// size
|
||||||
|
// TMP
|
||||||
unsigned int size() const;
|
unsigned int size() const;
|
||||||
|
// TMP END
|
||||||
|
// size_type size() const;
|
||||||
|
// max_size
|
||||||
|
// size_type max_size() const;
|
||||||
|
// resize
|
||||||
|
// void resize(size_type n, value_type val = value_type());
|
||||||
|
// capacity
|
||||||
|
size_type capacity() const;
|
||||||
|
// empty
|
||||||
|
// bool empty() const;
|
||||||
|
//reserve
|
||||||
|
// void reserve(size_type n);
|
||||||
|
|
||||||
|
/******************
|
||||||
|
* element access :
|
||||||
|
******************/
|
||||||
|
// operator[]
|
||||||
|
// reference operator[](size_type n);
|
||||||
|
// const_reference operator[](size_type n) const;
|
||||||
|
// at
|
||||||
|
// reference at(size_type n);
|
||||||
|
// const_reference at(size_type n) const;
|
||||||
|
// front
|
||||||
|
// reference front();
|
||||||
|
// const_reference front() const;
|
||||||
|
// back
|
||||||
|
// reference back();
|
||||||
|
// const_reference back() const;
|
||||||
|
|
||||||
|
/*************
|
||||||
|
* modifiers :
|
||||||
|
*************/
|
||||||
|
// assign
|
||||||
|
// template <class InputIterator>
|
||||||
|
// void assign(InputIterator first, InputIterator last);
|
||||||
|
// void assign(size_type n, const value_type& val);
|
||||||
|
// push_back
|
||||||
|
// TMP
|
||||||
void push_back(const int & element);
|
void push_back(const int & element);
|
||||||
|
// TMP END
|
||||||
|
// void push_back(const value_type& val);
|
||||||
|
// pop_back
|
||||||
|
// void pop_back();
|
||||||
|
// insert
|
||||||
|
// iterator insert(iterator position, const value_type& val);
|
||||||
|
// void insert(iterator position, size_type n, const value_type& val);
|
||||||
|
// template <class InputIterator>
|
||||||
|
// void insert(iterator position, InputIterator first, InputIterator last);
|
||||||
|
// erase
|
||||||
|
// iterator erase(iterator position);
|
||||||
|
// iterator erase(iterator first, iterator last);
|
||||||
|
// swap
|
||||||
|
// void swap(vector& x);
|
||||||
|
// clear
|
||||||
|
// void clear();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
unsigned int _size;
|
std::size_t _size;
|
||||||
int * _mem_ptr;
|
int * _mem_ptr;
|
||||||
std::allocator<int> _allocator;
|
std::allocator<int> _allocator;
|
||||||
|
|
||||||
// static std::string const ftvector::_bar;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//std::ostream & operator<<(std::ostream & o, ftvector const & rhs);
|
//std::ostream & operator<<(std::ostream & o, ftvector const & rhs);
|
||||||
|
|||||||
@@ -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"
|
#include "ftvector.hpp"
|
||||||
|
|
||||||
@@ -18,8 +7,9 @@
|
|||||||
* CONSTRUCTORS
|
* CONSTRUCTORS
|
||||||
*********************************************/
|
*********************************************/
|
||||||
|
|
||||||
ftvector::ftvector() :
|
ftvector::ftvector()
|
||||||
_size(0) {
|
: _size(0)
|
||||||
|
, _space(0) {
|
||||||
// std::cout << COPLIEN_COLOR "ftvector constructor" RESET "\n";
|
// std::cout << COPLIEN_COLOR "ftvector constructor" RESET "\n";
|
||||||
_allocator = std::allocator<int>();
|
_allocator = std::allocator<int>();
|
||||||
return;
|
return;
|
||||||
@@ -70,9 +60,35 @@ unsigned int ftvector::size() const {return _size;}
|
|||||||
*********************************************/
|
*********************************************/
|
||||||
|
|
||||||
void ftvector::push_back(const int & element) {
|
void ftvector::push_back(const int & element) {
|
||||||
_mem_ptr = _allocator.allocate(1);
|
if (_size == _space)
|
||||||
_allocator.construct(_mem_ptr, element);
|
hold_space(1);
|
||||||
|
_allocator.construct(&_mem_ptr[_size], element);
|
||||||
_size++;
|
_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************
|
/*********************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user