|
@ -1,6 +1,7 @@ |
|
|
#pragma once |
|
|
#pragma once |
|
|
#include "iterator.hpp" |
|
|
#include "iterator.hpp" |
|
|
#include <memory> |
|
|
#include <memory> |
|
|
|
|
|
#include <stdexcept> |
|
|
|
|
|
|
|
|
namespace ft { |
|
|
namespace ft { |
|
|
|
|
|
|
|
@ -62,7 +63,18 @@ public: |
|
|
_alloc.deallocate(_begin, _capacity); |
|
|
_alloc.deallocate(_begin, _capacity); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
vector &operator=(const vector &other); |
|
|
vector &operator=(const vector &other) { |
|
|
|
|
|
clear(); |
|
|
|
|
|
_alloc.deallocate(_begin, _capacity); |
|
|
|
|
|
_alloc = other._alloc; |
|
|
|
|
|
_capacity = other._capacity; |
|
|
|
|
|
_size = other._size; |
|
|
|
|
|
_begin = _alloc.allocate(_capacity); |
|
|
|
|
|
for (size_type i = 0; i < _size; i++) |
|
|
|
|
|
_alloc.construct(_begin + i, *(other._begin + i)); |
|
|
|
|
|
return (*this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void assign(size_type count, const T &value); |
|
|
void assign(size_type count, const T &value); |
|
|
template < class It > void assign(It first, It last); |
|
|
template < class It > void assign(It first, It last); |
|
|
allocator_type get_allocator(void) const { return _alloc; } |
|
|
allocator_type get_allocator(void) const { return _alloc; } |
|
@ -97,11 +109,24 @@ public: |
|
|
ft::rev_iterator< cst_iterator > rend(void) const; |
|
|
ft::rev_iterator< cst_iterator > rend(void) const; |
|
|
|
|
|
|
|
|
// CAPACITY:
|
|
|
// CAPACITY:
|
|
|
bool empty(void) const; |
|
|
bool empty(void) const { return _size == 0; } |
|
|
size_type size(void) const; |
|
|
size_type size(void) const { return _size; } |
|
|
size_type max_size(void) const; |
|
|
size_type max_size(void) const { return _alloc.max_size(); } |
|
|
void reserve(size_type new_cap); |
|
|
void reserve(size_type new_cap) { |
|
|
size_type capacity(void) const; |
|
|
if (new_cap > max_size()) |
|
|
|
|
|
throw(std::length_error("vector::reserve: new_cap > max_size")); |
|
|
|
|
|
Allocator new_alloc; |
|
|
|
|
|
pointer new_begin; |
|
|
|
|
|
new_begin = new_alloc.allocate(new_cap); |
|
|
|
|
|
for (size_type i = 0; i < _size; i++) |
|
|
|
|
|
new_alloc.construct(new_begin + i, *(_begin + i)); |
|
|
|
|
|
clear(); |
|
|
|
|
|
_alloc.deallocate(_begin, _capacity); |
|
|
|
|
|
_alloc = new_alloc; |
|
|
|
|
|
_begin = new_begin; |
|
|
|
|
|
_capacity = new_cap; |
|
|
|
|
|
} |
|
|
|
|
|
size_type capacity(void) const { return _capacity; } |
|
|
|
|
|
|
|
|
// MODIFIERS:
|
|
|
// MODIFIERS:
|
|
|
void clear(void) { |
|
|
void clear(void) { |
|
@ -114,12 +139,11 @@ public: |
|
|
template < class It > iterator insert(cst_iterator pos, It first, It last); |
|
|
template < class It > iterator insert(cst_iterator pos, It first, It last); |
|
|
iterator erase(iterator pos); |
|
|
iterator erase(iterator pos); |
|
|
iterator erase(iterator first, iterator last); |
|
|
iterator erase(iterator first, iterator last); |
|
|
void push_back(const T& value); |
|
|
void push_back(const T &value); |
|
|
void pop_back(void); |
|
|
void pop_back(void); |
|
|
void resize(size_type count); |
|
|
void resize(size_type count); |
|
|
void resize(size_type count, T value = T()); |
|
|
void resize(size_type count, T value = T()); |
|
|
void swap( vector& other); |
|
|
void swap(vector &other); |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
} // namespace ft
|
|
|
} // namespace ft
|
|
|