Boost logo

Boost :

Subject: [boost] GSoC '15 Enhanced Vector and Deque
From: Pranav Vaish (pranav.vaish_at_[hidden])
Date: 2015-03-12 14:39:58


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<<e.what()<<std::endl;
}
}
}

#endif

As I am new to contributing for Open Source, I'm not sure if sending links
on this mailing list is disrespectful or not. If it is I apologize for
this. Code can be found on https://github.com/vaishious/boost.vector

Thanks
-Pranav


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk