Skip to content

Instantly share code, notes, and snippets.

@wbadart
Created May 4, 2016 02:57
Show Gist options
  • Save wbadart/3529bfb1a9cc8927f7066430e132f4a7 to your computer and use it in GitHub Desktop.
Save wbadart/3529bfb1a9cc8927f7066430e132f4a7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
template<typename T>
class container{
public:
container();
T* begin();
T* end();
void push_back(T);
private:
T* head;
T* tail;
int len;
};
using namespace std;
template<typename T>
container<T>::container():len(0){
head = new T;
}
template<typename T>
T* container<T>::begin(){
return head;
}
template<typename T>
T* container<T>::end(){
return (head + len);
}
template<typename T>
void container<T>::push_back(T d){
*(head + len++) = d;
tail++;
}
int main(void){
container<int> a;
a.push_back(5);
a.push_back(10);
for(auto i: a){
cout << i << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment