Neat Vectors  5
Hanes
vector.h
Go to the documentation of this file.
1 
6 #ifndef VECTOR_H
7 #define VECTOR_H
8 
9 #include<stdexcept>
10 using std::invalid_argument;
11 #include<iostream>
12 using std::ostream;
13 
14 #ifndef DOXYGEN
15 template<class FUN>
16 class Vector;
17 #endif
18 
27 template<class FUN>
28 ostream& operator<<(ostream& out, const Vector<FUN>& v);
29 
36 template<class FUN>
37 class Vector
38 {
39  public:
44  Vector();
45 
51  Vector(const Vector<FUN>& v);
52 
54  ~Vector();
55 
62  void push_back(FUN v);
63 
72  FUN& operator[](const unsigned int idx);
73 
82  const FUN& operator[](const unsigned int idx) const;
83 
88  unsigned int length() const;
89 
94  unsigned int size() const;
95 
96 #ifndef DOXYGEN
97  /* Doxygen appears to have a couple bugs related to template classes and friend functions.
98  * At this point, the best fix I see is to set
99  * PREDEFINED = DOXYGEN
100  * in your Doxyfile, then use #ifndef DOXYGEN / #endif to remove code that confuses Doxygen.
101  *
102  * Note that this function is documented at the top of the file and uses the \relatesalso
103  * command so that it will be included on the Vector class docs page.
104  */
105  friend ostream& operator<< <FUN>(ostream& out, const Vector<FUN>& v);
106 #endif
107  private:
108  unsigned int sz;
109  unsigned int max;
110  FUN* array;
111 };
112 
113 #include"vector.hpp"
114 #endif
Vector()
Constructs an empty vector.
Definition: vector.hpp:3
A (very neat) vector.
Definition: vector.h:37
FUN & operator[](const unsigned int idx)
Reads an element of the vector.
Definition: vector.hpp:54
unsigned int size() const
The size of the underlying storage.
Definition: vector.hpp:85
unsigned int length() const
The number of items stored in the vector.
Definition: vector.hpp:78
~Vector()
Destructor.
Definition: vector.hpp:25
void push_back(FUN v)
Add elements to the vector.
Definition: vector.hpp:32