From be2676e56ae0c72321c60c4848ce720ccf095b26 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 1 Feb 2020 14:17:04 +0100 Subject: Remaking List, Removed include/, test/ and Makefile --- include/Vector.hpp | 128 ----------------------------------------------------- 1 file changed, 128 deletions(-) delete mode 100644 include/Vector.hpp (limited to 'include/Vector.hpp') diff --git a/include/Vector.hpp b/include/Vector.hpp deleted file mode 100644 index 0f21995..0000000 --- a/include/Vector.hpp +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef VECTOR_HPP -# define VECTOR_HPP - -# include - -# define GROWTH_FACTOR 1.5 - -typedef size_t size_type; - - -namespace ft -{ - template < class T, class Alloc = allocator > - class vector - { - typedef T value_type; - typedef T& reference; - - public: - // capacity - size_type size() const; - { - return size; - } - void resize (size_type n, value_type val = value_type()) - { - if (n < size) - { - for (int i = n; i < size; i++) - ~T(under[i]); - size = n; - return; - } - if (n > capacity) - grow(); - size_type prev_n; - for (prev_n = n; prev_n < size; prev_n++) - under[n] = val; - size = n; - } - size_type capacity() const - { - return capacity; - } - bool empty() const - { - return size == 0; - } - void reserve (size_type n) - { - if (n > capacity) - grow_to(n); - } - - // element access - reference operator[] (size_type n) - { - return under[n]; - } - reference at (size_type n) - { - if (n >= size) - raise std::out_of_range; - return under[n]; - } - reference front() - { - return under[0]; - } - reference back() - { - return under[size - 1]; - } - - // modifiers - template - void assign (InputIterator first, InputIterator last); - void assign (size_type n, const value_type& val); - void push_back (const value_type& val) - { - if (size >= capacity) - grow(); - under[size] = val; - size++; - } - void pop_back() - { - ~T(back()); - size--; - } - iterator insert (iterator position, const value_type& val) - { - - } - void insert (iterator position, size_type n, const value_type& val); - template - void insert (iterator position, InputIterator first, InputIterator last); - - - - - private: - T *under; - size_type size; - size_type capacity; - - void grow() - { - capacity *= GROWTH_FACTOR; - grow_to(capacity); - } - - void grow_to(size_type new_capacity) - { - T *under_copy = new T[capacity]; - for (int i = 0; i < capacity; i++) - under_copy[i] = under[i]; - delete [] under; - capacity = new_capacity; - under = new T[capacity]; - for (int i = 0; i < capacity; i++) - under[i] = under_copy[i]; - delete [] under_copy; - } - }; -} - -#endif -- cgit