added resize and _increment_capacity

This commit is contained in:
hugogogo
2022-06-09 14:14:13 +02:00
parent b385f6220a
commit 8326f7f283
3 changed files with 348 additions and 135 deletions

View File

@@ -1,11 +1,14 @@
#ifndef VECTOR_HPP
# define VECTOR_HPP
# include "colors.h"
# include <iostream>
# include <string>
# include <memory> // std::allocator
# include <algorithm> // std::min
# include <stdexcept> // out_of_range, length_error, logic_error
# include <cstddef> // NULL, size_t, ptrdiff_t
# include "colors.h"
# include "enable_if.hpp"
# include "is_integral.hpp"
@@ -13,24 +16,34 @@ namespace ft {
template <
class T,
class Allocator = std::allocator<T>
> class vector {
class Allocator = std::allocator<T> >
class vector {
public:
typedef T value_type;
typedef Allocator allocator_type;
typedef std::size_t size_type;
typedef T value_type;
typedef Allocator allocator_type;
typedef std::size_t size_type;
// typedef std::ptrdiff_t difference_type;
typedef T * iterator;
typedef T * iterator;
typedef T const * const_iterator;
// typedef ft::reverse_iterator<iterator> reverse_iterator;
// typedef ft::reverse_iterator<const_iterator> const_reverse_iterator;
// dependent qualified name :
// https://en.cppreference.com/w/cpp/keyword/typename
typedef typename Allocator::reference reference;
typedef typename Allocator::const_reference const_reference;
// typedef typename Allocator::pointer pointer;
// typedef typename Allocator::const_pointer const_pointer;
typedef typename allocator_type::reference reference;
/************
* copliens :
************/
// constructor -------------------------------
// constructors ------------------------------
explicit vector (const allocator_type & alloc = allocator_type());
explicit vector (size_type n, const value_type& val = value_type(),
const allocator_type& alloc = allocator_type());
@@ -66,13 +79,13 @@ public:
// size --------------------------------------
size_type size() const;
// max_size ----------------------------------
//size_type max_size() const;
size_type max_size() const;
// resize ------------------------------------
//void resize(size_type n, value_type val = value_type());
void resize(size_type n, value_type val = value_type());
// capacity ----------------------------------
size_type capacity() const;
// empty -------------------------------------
//bool empty() const;
bool empty() const;
// reserve -----------------------------------
void reserve(size_type n);
@@ -81,16 +94,16 @@ public:
******************/
// operator[] --------------------------------
reference operator[](size_type n);
//const_reference operator[](size_type n) const;
const_reference operator[](size_type n) const;
// at ----------------------------------------
//reference at(size_type n);
//const_reference at(size_type n) const;
reference at(size_type n);
const_reference at(size_type n) const;
// front -------------------------------------
//reference front();
//const_reference front() const;
reference front();
const_reference front() const;
// back --------------------------------------
//reference back();
//const_reference back() const;
reference back();
const_reference back() const;
/*************
* modifiers :
@@ -126,6 +139,7 @@ private:
allocator_type _allocator;
void _destroy(iterator first, iterator last);
void _increment_capacity(size_type n);
};