diff options
author | kdx <kdx.42@42l.fr> | 2023-01-17 11:44:39 +0100 |
---|---|---|
committer | kdx <kdx.42@42l.fr> | 2023-01-17 11:44:39 +0100 |
commit | fc6f771143a0d60055f9a7ce0e6559089ab59349 (patch) | |
tree | 9962bd9dc7a13e68488c82e0420ced9d16d0945c | |
parent | fa60aae63b4e2c743627741bb4ca10eb4f12bb80 (diff) | |
download | 42-containers-fc6f771143a0d60055f9a7ce0e6559089ab59349.tar.gz |
iterator contructor
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | vector.hpp | 14 |
2 files changed, 13 insertions, 3 deletions
@@ -20,7 +20,7 @@ int main() other.push_back(8); std::for_each(other.begin(), other.end(), print); std::cout << std::endl; - const vector<int> constvec(other); + const vector<int> constvec(other.rbegin(), other.rend()); std::for_each(constvec.rbegin(), constvec.rend(), print); std::cout << std::endl; other.pop_back(); @@ -3,6 +3,7 @@ #include <limits> #include <cstddef> #include <stdexcept> +#include <iostream> namespace ft { template < @@ -145,7 +146,15 @@ public: vector(InputIt first, InputIt last, const Allocator& alloc = Allocator()) { - /* TODO */ + _alloc = alloc; + _size = 0; + while (first + _size != last) + _size += 1; + _capacity = _size; + if (_capacity > 0) + _data = _alloc.allocate(_capacity); + for (size_type i = 0; i < _size; i++) + _alloc.construct(_data + i, *(first + i)); } vector(const vector& other) : _data(NULL) @@ -190,12 +199,13 @@ public: /* assign */ void assign(size_type count, const T& value) { - *this = vector(count, value); + *this = vector(count, value, _alloc); } template<class InputIt> void assign(InputIt first, InputIt last) { + *this = vector(first, last, _alloc); /* TODO */ } |