online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include<map> #include<string> #include<vector> namespace ft { template <class _Iter> struct iterator_traits { }; template <class T> struct iterator_traits<T*> { typedef T* pointer; }; template <class T> class wrap_iter { public: typedef T iter_type; typedef typename ft::iterator_traits<iter_type>::pointer pointer; private: pointer ptr; unsigned int sz; int index; public: wrap_iter(pointer arr, unsigned int sz, int begin): ptr(arr), sz(sz) { if (begin) this->index = 0; else this->index = sz; } ~wrap_iter() {} T &operator*() const { if (this->index == (int)this->sz) throw std::out_of_range("Trying to access wrong index"); return (ptr[this->index]); } }; template <class T, class A = std::allocator<T> > class vector { public: typedef typename A::size_type size_type; typedef typename A::pointer pointer; typedef ft::wrap_iter<pointer> iterator; private: pointer arr; size_type capacity; size_type sz; public: vector() : arr(new T[1]), capacity(1), sz(0) { } vector(iterator begin, iterator end) { for (iterator it = begin; it != end; ++it) { if (this->sz == this->capacity) { this->reserve(2 * this->capacity); } this->arr[sz] = *it; sz++; } } void push_back(T element) { if (this->sz == this->capacity) { this->reserve(2 * this->capacity); } this->arr[sz] = element; sz++; } void reserve(size_type am) { if (am > this->capacity) { T *temp = new T[am]; for (size_type i = 0; i < this->capacity; ++i) temp[i] = this->arr[i]; delete[] this->arr; capacity = am; this->arr = temp; } } iterator begin() { return (iterator(this->arr, this->sz, 1)); } iterator end() { return (iterator(this->arr, this->sz, 0)); } }; } int main() { ft::vector<int> vec; vec.push_back(5); vec.push_back(10); vec.push_back(15); vec.push_back(14); ft::vector<int>::iterator it = vec.begin(); std::cout << *it << std::endl; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue