#ifndef _SVECTOR_H_
#define _SVECTOR_H_
#include <iterator> // for std::iterator
//******************************************************************************
//******************************************************************************
//******************************************************************************
// svector
template <typename T>
class svector
{
private:
//******************************************************************************
// svector_iter
class svector_iter : public std::iterator<std::random_access_iterator_tag, T>
{
public:
// Typedefs for our use
typedef std::random_access_iterator_tag iterator_category;
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef T& reference;
svector_iter(); // default constructor
svector_iter(pointer); // conversion constructor
difference_type operator-(const svector_iter& rhs);
svector_iter operator+(difference_type rhs);
reference operator[](difference_type index);
private:
pointer elem_ptr_; // A pointer to some element
};
//******************************************************************************
// const_svector_iter
class const_svector_iter : public std::iterator<std::random_access_iterator_tag, T>
{
public:
typedef std::random_access_iterator_tag iterator_category;
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef const T* pointer;
typedef const T& reference;
const_svector_iter(); // default constructor
const_svector_iter(pointer); // conversion constructor
reference operator*(void) const;
const_svector_iter& operator++(void);
bool operator!=(const const_svector_iter &rhs) const;
private:
pointer elem_ptr_; // A pointer to some element
};
//******************************************************************************
// svector
public:
// Typedefs required for STL compatibility
typedef T value_type; // type in the container
typedef T& reference; // ref type in container
typedef const T& const_reference; // const ref type in container
typedef svector_iter iterator; // iterator type for this container
typedef const_svector_iter const_iterator; // const iterator type
typedef ptrdiff_t difference_type; // type of diff between iterators
typedef unsigned int size_type; // type of sizes in container
svector();
~svector();
iterator begin(void);
iterator end(void);
const_iterator begin(void) const;
const_iterator end(void) const;
size_type size(void) const;
void push_back(const_reference value);
iterator insert(iterator it, const_reference value);
void clear(void);
private:
size_type size_; // The number of elements in the array
T* array_; // The dynamically allocated array
size_type capacity_; // The allocated size of the array
void grow(void);
};
#include "svector.cpp"
#endif