Hello,
My name is Pranav. I had sent an email on this mailing list earlier
regarding some doubt in the implementation of the programming competency
test for this project. I have gone ahead and written some code.
The code is incomplete. Iterator code has not yet been written and
container methods and some error handling is left. I would appreciate it if
someone could review my code and tell me what else I will need to implement.
#ifndef BOOST_VECTOR
#define BOOST_VECTOR
#include<exception>
#include<iostream>
struct exception_push_back_capacity_exceed : public std::exception
{
const char * what () const throw ()
{
return "Vector Capacity Exceeded";
}
};
namespace boost
{
template<typename T> class vector
{
public:
vector(int);
~vector();
void push_back(T);
T operator[](const int& pos)
{
return *(mem_start+pos);
}
private:
T* mem_start;
int size;
int capacity;
};
template<typename T> vector<T>::vector(int capacity_constr)
{
size=0;
capacity=capacity_constr;
mem_start = new T[capacity];
}
template<typename T> vector<T>::~vector()
{
delete [] mem_start;
}
template<typename T> void vector<T>::push_back(T val)
{
try
{
if(size==(this->capacity))
{
throw exception_push_back_capacity_exceed();
}
mem_start[size++]=val;
}
catch(exception_push_back_capacity_exceed& e)
{
std::cout<