second vector start

This commit is contained in:
kinou-p 2022-10-24 10:06:12 +02:00
parent 5f0dfe405e
commit 1922da7816
4 changed files with 326 additions and 25 deletions

15
commentary_for_header Normal file
View File

@ -0,0 +1,15 @@
//-----------------------------
//---------MEMBER TYPE---------
//-----------------------------
//---------------------------------------
//---------COPLIEN FORM FUNCTION---------
//---------------------------------------
//----------------------------------
//---------MEMBER FUNCTION----------
//----------------------------------
//---------------------------------------------
//---------OPERATOR OVERLOAD FUNCTION----------
//---------------------------------------------

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 19:46:30 by apommier #+# #+# */ /* Created: 2022/10/12 19:46:30 by apommier #+# #+# */
/* Updated: 2022/10/19 17:22:33 by apommier ### ########.fr */ /* Updated: 2022/10/21 13:43:05 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,7 +23,9 @@ class stack
{ {
public: public:
//-----------------------------
//---------MEMBER TYPE--------- //---------MEMBER TYPE---------
//-----------------------------
typedef std::size_t size_type; typedef std::size_t size_type;
typedef T value_type; typedef T value_type;
typedef Container container_type; typedef Container container_type;
@ -32,7 +34,10 @@ class stack
container_type c; container_type c;
public: public:
//---------------------------------------
//---------COPLIEN FORM FUNCTION--------- //---------COPLIEN FORM FUNCTION---------
//---------------------------------------
explicit stack (const container_type& ctnr = container_type()) : c(ctnr){}//default constructor explicit stack (const container_type& ctnr = container_type()) : c(ctnr){}//default constructor
stack<T, Container>(const stack &other )//copy constructor stack<T, Container>(const stack &other )//copy constructor
{ {
@ -45,7 +50,10 @@ class stack
this->c = other.c; this->c = other.c;
return *this; return *this;
} }
//----------------------------------
//---------MEMBER FUNCTION---------- //---------MEMBER FUNCTION----------
//----------------------------------
bool empty() const bool empty() const
{ {
return (c.empty()); return (c.empty());
@ -75,6 +83,47 @@ class stack
{ {
return (c.pop_back()); return (c.pop_back());
} }
//---------------------------------------------
//---------OPERATOR OVERLOAD FUNCTION----------
//---------------------------------------------
// template <class T, class Container>
// bool operator== (const stack<T,Container>& lhs, const stack<T,Container>& rhs)
// {
// }
// template <class T, class Container>
// bool operator!= (const stack<T,Container>& lhs, const stack<T,Container>& rhs)
// {
// }
// template <class T, class Container>
// bool operator< (const stack<T,Container>& lhs, const stack<T,Container>& rhs)
// {
// }
// template <class T, class Container>
// bool operator<= (const stack<T,Container>& lhs, const stack<T,Container>& rhs)
// {
// }
// template <class T, class Container>
// bool operator> (const stack<T,Container>& lhs, const stack<T,Container>& rhs)
// {
// }
// template <class T, class Container>
// bool operator>= (const stack<T,Container>& lhs, const stack<T,Container>& rhs)
// {
// }
}; };
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 19:46:32 by apommier #+# #+# */ /* Created: 2022/10/12 19:46:32 by apommier #+# #+# */
/* Updated: 2022/10/19 17:30:38 by apommier ### ########.fr */ /* Updated: 2022/10/23 19:58:10 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,35 +16,272 @@
namespace ft namespace ft
{ {
template< class T, class Allocator = std::allocator<T> > class vector; template< class T, class Allocator = std::allocator<T> >
class vector class vector
{ {
public: public:
//-----------------------------
//---------MEMBER TYPE--------- //---------MEMBER TYPE---------
typedef value_type; //-----------------------------
typedef allocator_type; typedef T value_type;
typedef reference; typedef Allocator allocator_type;
typedef const_reference; typedef value_type& reference;
typedef pointer; typedef const value_type& const_reference;
typedef const_pointer; typedef typename Allocator::pointer pointer;
typedef iterator; typedef typename Allocator::const_pointer const_pointer;
typedef const_iterator; typedef value_type iterator;
typedef reverse_iterator; typedef value_type const_iterator;
typedef const_reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator;
typedef difference_type; typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef size_type; typedef std::ptrdiff_t difference_type;
typedef std::size_t size_type;
//---------------------------------------
//---------COPLIEN FORM FUNCTION--------- //---------COPLIEN FORM FUNCTION---------
explicit vector (const allocator_type& alloc = allocator_type());//default constructor //---------------------------------------
explicit vector (size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type());//fill constructor explicit vector (const allocator_type& alloc = allocator_type()) : _allocator(alloc) //default constructor
{
_tab = 0
_size = 0
_capacity = 0
}
explicit vector (size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type()): _allocator(alloc) //fill constructor
{
_tab =
_size =
_capacity =
}
template <class InputIterator> template <class InputIterator>
vector (InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());//range constructor vector (InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type()) //range constructor
vector (const vector& x);//copy constructor {
~vector();
vector& operator= (const vector& x);//assignation operator }
vector (const vector& x)//copy constructor
{
}
~vector()
{
}
vector& operator= (const vector& x)//assignation operator
{
}
//----------------------------------
//---------MEMBER FUNCTION---------- //---------MEMBER FUNCTION----------
//----------------------------------
//-------------------------
//--------Iterators--------
//-------------------------
//------------------------
//--------Capacity--------
//------------------------
size_type size() const
{
return (_size);
}
size_type max_size() const
{
return (_allocator.max_size());
}
void resize (size_type n, value_type val = value_type()) //Resizes the container so that it contains n elements.
{
}
size_type capacity() const
{
return (_capacity);
}
bool empty() const
{
if (!_size)
return (1);
return(0);
}
void reserve (size_type n)
{
}
//------------------------------
//--------Element access--------
//------------------------------
reference operator[] (size_type n)
{
return (_tab[n]);
}
const_reference operator[] (size_type n) const
{
return (_tab[n]);
}
reference at (size_type n)
{
//exception
return (_tab[n]);
}
const_reference at (size_type n) const
{
//exception
return (_tab[n]);
}
reference front()
{
}
const_reference front() const
{
}
reference back()
{
}
const_reference back() const
{
}
value_type* data()
{
}
const value_type* data() const
{
}
//-------------------------
//--------Modifiers--------
//-------------------------
template <class InputIterator>
void assign (InputIterator first, InputIterator last) //range
{
}
void assign (size_type n, const value_type& val) //fill
{
}
void push_back (const value_type& val)
{
}
void pop_back()
{
}
iterator insert (iterator position, const value_type& val) //single element
{
}
void insert (iterator position, size_type n, const value_type& val) //fill
{
}
template <class InputIterator>
void insert (iterator position, InputIterator first, InputIterator last) //range
{
}
iterator erase (iterator position);iterator erase (iterator first, iterator last)
{
}
void swap (vector& x)
{
}
void clear()
{
}
//-------------------------
//--------Allocator--------
//-------------------------
allocator_type get_allocator() const
{
return (_allocator);
}
//---------------------------------------------
//---------OPERATOR OVERLOAD FUNCTION----------
//---------------------------------------------
// template <class T, class Alloc>
// bool operator== (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs)
// {
// }
// template <class T, class Alloc>
// bool operator!= (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs)
// {
// }
// template <class T, class Alloc>
// bool operator< (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs)
// {
// }
// template <class T, class Alloc>
// bool operator<= (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs)
// {
// }
// template <class T, class Alloc>
// bool operator> (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs)
// {
// }
// template <class T, class Alloc>
// bool operator>= (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs)
// {
// }
private: private:
value_type *_tab;
size_type _size;
size_type _capacity;
allocator_type _allocator;
}; };
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 19:46:35 by apommier #+# #+# */ /* Created: 2022/10/12 19:46:35 by apommier #+# #+# */
/* Updated: 2022/10/12 19:46:56 by apommier ### ########.fr */ /* Updated: 2022/10/19 18:35:21 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -83,7 +83,7 @@ int main(int argc, char** argv) {
{ {
const int idx = rand() % COUNT; const int idx = rand() % COUNT;
vector_buffer[idx].idx = 5; vector_buffer[idx].idx = 5;
} }
ft::vector<Buffer>().swap(vector_buffer); ft::vector<Buffer>().swap(vector_buffer);
try try