Browse Source

save 5-12-22

master
narnaud 2 years ago
parent
commit
89fec72cdd
  1. BIN
      .cache/clangd/index/ft_container.hpp.AE6A49ED28E963FF.idx
  2. BIN
      .cache/clangd/index/iterator.hpp.B6BE3296FFA2AF9F.idx
  3. BIN
      .cache/clangd/index/tester.cpp.133FD4700F7AEE0A.idx
  4. BIN
      .cache/clangd/index/vector.hpp.8C3201A34AC2A736.idx
  5. 42
      includes/vector.hpp

BIN
.cache/clangd/index/ft_container.hpp.AE6A49ED28E963FF.idx

Binary file not shown.

BIN
.cache/clangd/index/iterator.hpp.B6BE3296FFA2AF9F.idx

Binary file not shown.

BIN
.cache/clangd/index/tester.cpp.133FD4700F7AEE0A.idx

Binary file not shown.

BIN
.cache/clangd/index/vector.hpp.8C3201A34AC2A736.idx

Binary file not shown.

42
includes/vector.hpp

@ -1,6 +1,7 @@
#pragma once
#include "iterator.hpp"
#include <memory>
#include <stdexcept>
namespace ft {
@ -62,7 +63,18 @@ public:
_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);
template < class It > void assign(It first, It last);
allocator_type get_allocator(void) const { return _alloc; }
@ -97,11 +109,24 @@ public:
ft::rev_iterator< cst_iterator > rend(void) const;
// CAPACITY:
bool empty(void) const;
size_type size(void) const;
size_type max_size(void) const;
void reserve(size_type new_cap);
size_type capacity(void) const;
bool empty(void) const { return _size == 0; }
size_type size(void) const { return _size; }
size_type max_size(void) const { return _alloc.max_size(); }
void reserve(size_type new_cap) {
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:
void clear(void) {
@ -114,12 +139,11 @@ public:
template < class It > iterator insert(cst_iterator pos, It first, It last);
iterator erase(iterator pos);
iterator erase(iterator first, iterator last);
void push_back(const T& value);
void push_back(const T &value);
void pop_back(void);
void resize(size_type count);
void resize(size_type count, T value = T());
void swap( vector& other);
void swap(vector &other);
};
} // namespace ft

Loading…
Cancel
Save