Use better filename for pull request
[TortoiseGit.git] / src / Utils / stdex_vector.h
blobdce4102c742e4f4021d1f948283872a41a49614a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006 - Stefan Kueng
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 #include <vector>
23 namespace stdex {
25 /**
26 * Subclass of the STL's vector class that allows the class to be used more
27 * freely in place of a C-style array.
28 * @author Damian Powell
30 template <class T, class Al = std::allocator<T> >
31 class vector : public std::vector<T, Al> {
33 public:
35 /**
36 * Default constructor creates an empty vector.
38 inline vector()
39 { }
41 /**
42 * Creates a vector of n items where each item is initialized to its
43 * default value as defined by 'T()'
44 * @param n The number of items to allocate in the new vector.
46 inline vector(size_type n)
47 : std::vector<T, Al> (n)
48 { }
50 /**
51 * Creates a vector of n items where each item is initialized to the
52 * specified value t.
53 * @param n The number of items to allocate in the new vector.
54 * @param t The value that each new item shall be initialized to.
56 inline vector(size_type n, const T& t)
57 : std::vector<T, Al> (n, t)
58 { }
60 /**
61 * Index operator returns reference to the specified immutable item.
62 * No additional bounds checking is performed.
63 * @param i The index of the value to return a reference to.
64 * @return An immutable reference to the item at index i.
66 inline const_reference operator [] (size_type i) const {
67 ASSERT(i < size());
68 return std::vector<T, Al>::operator [] (i);
71 /**
72 * Index operator returns a reference to the specified item. No
73 * additional bounds checking is performed.
74 * @param i The index of the value to return a reference to.
75 * @return A reference to the item at index i.
77 inline reference operator [] (size_type i) {
78 ASSERT(i < size());
79 return std::vector<T, Al>::operator [] (i);
82 /**
83 * Conversion operator returns pointer to the immutable item at the
84 * beginning of this array of NULL if the array is empty.
85 * @param i The index of the value to return a reference to.
86 * @return A pointer to an immutable item or NULL.
88 inline operator const_pointer () const {
89 return empty() ? NULL : &operator[](0);
92 /**
93 * Conversion operator returns pointer to the item at the beginning of
94 * this array of NULL if the array is empty.
95 * @param i The index of the value to return a reference to.
96 * @return A pointer to an item or NULL.
98 inline operator pointer () {
99 return empty() ? NULL : &operator[](0);