Skip to content

Commit 1fd8af5

Browse files
committed
express: add C++11 methods to ordered_vector
1 parent 84520ce commit 1fd8af5

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

panda/src/express/ordered_vector.I

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,44 @@ rend() const {
109109
return _vector.rend();
110110
}
111111

112+
/**
113+
* Returns the iterator that marks the first element in the ordered vector.
114+
*/
115+
template<class Key, class Compare, class Vector>
116+
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_ITERATOR ordered_vector<Key, Compare, Vector>::
117+
cbegin() const {
118+
return _vector.begin();
119+
}
120+
121+
/**
122+
* Returns the iterator that marks the end of the ordered vector.
123+
*/
124+
template<class Key, class Compare, class Vector>
125+
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_ITERATOR ordered_vector<Key, Compare, Vector>::
126+
cend() const {
127+
return _vector.end();
128+
}
129+
130+
/**
131+
* Returns the iterator that marks the first element in the ordered vector,
132+
* when viewed in reverse order.
133+
*/
134+
template<class Key, class Compare, class Vector>
135+
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_REVERSE_ITERATOR ordered_vector<Key, Compare, Vector>::
136+
crbegin() const {
137+
return _vector.rbegin();
138+
}
139+
140+
/**
141+
* Returns the iterator that marks the end of the ordered vector, when viewed
142+
* in reverse order.
143+
*/
144+
template<class Key, class Compare, class Vector>
145+
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_REVERSE_ITERATOR ordered_vector<Key, Compare, Vector>::
146+
crend() const {
147+
return _vector.rend();
148+
}
149+
112150
/**
113151
* Returns the nth element.
114152
*/
@@ -127,6 +165,54 @@ operator [] (TYPENAME ordered_vector<Key, Compare, Vector>::SIZE_TYPE n) const {
127165
return _vector[n];
128166
}
129167

168+
/**
169+
* Returns a reference to the first element.
170+
*/
171+
template<class Key, class Compare, class Vector>
172+
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::REFERENCE ordered_vector<Key, Compare, Vector>::
173+
front() {
174+
#ifdef _DEBUG
175+
assert(!_vector.empty());
176+
#endif
177+
return _vector[0];
178+
}
179+
180+
/**
181+
* Returns a const reference to the first element.
182+
*/
183+
template<class Key, class Compare, class Vector>
184+
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_REFERENCE ordered_vector<Key, Compare, Vector>::
185+
front() const {
186+
#ifdef _DEBUG
187+
assert(!_vector.empty());
188+
#endif
189+
return _vector[0];
190+
}
191+
192+
/**
193+
* Returns a reference to the first element.
194+
*/
195+
template<class Key, class Compare, class Vector>
196+
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::REFERENCE ordered_vector<Key, Compare, Vector>::
197+
back() {
198+
#ifdef _DEBUG
199+
assert(!_vector.empty());
200+
#endif
201+
return _vector[_vector.size() - 1];
202+
}
203+
204+
/**
205+
* Returns a const reference to the last element.
206+
*/
207+
template<class Key, class Compare, class Vector>
208+
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_REFERENCE ordered_vector<Key, Compare, Vector>::
209+
back() const {
210+
#ifdef _DEBUG
211+
assert(!_vector.empty());
212+
#endif
213+
return _vector[_vector.size() - 1];
214+
}
215+
130216
/**
131217
* Returns the number of elements in the ordered vector.
132218
*/
@@ -530,6 +616,18 @@ push_back(const value_type &key) {
530616
_vector.push_back(key);
531617
}
532618

619+
/**
620+
* Adds the new element to the end of the vector without regard for proper
621+
* sorting. This is a bad idea to do except to populate the vector the first
622+
* time; be sure to call sort() after you have added all the elements.
623+
*/
624+
template<class Key, class Compare, class Vector>
625+
INLINE void ordered_vector<Key, Compare, Vector>::
626+
push_back(value_type &&key) {
627+
TAU_PROFILE("ordered_vector::push_back()", " ", TAU_USER);
628+
_vector.push_back(move(key));
629+
}
630+
533631
/**
534632
* Removes the last element at the end of the vector.
535633
*/

panda/src/express/ordered_vector.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,21 @@ class ordered_vector {
147147
INLINE CONST_REVERSE_ITERATOR rbegin() const;
148148
INLINE CONST_REVERSE_ITERATOR rend() const;
149149

150+
INLINE CONST_ITERATOR cbegin() const;
151+
INLINE CONST_ITERATOR cend() const;
152+
INLINE CONST_REVERSE_ITERATOR crbegin() const;
153+
INLINE CONST_REVERSE_ITERATOR crend() const;
154+
150155
// Random access.
151156
INLINE reference operator [] (SIZE_TYPE n);
152157
INLINE const_reference operator [] (SIZE_TYPE n) const;
153158

159+
INLINE reference front();
160+
INLINE const_reference front() const;
161+
162+
INLINE reference back();
163+
INLINE const_reference back() const;
164+
154165
// Size information.
155166
INLINE SIZE_TYPE size() const;
156167
INLINE SIZE_TYPE max_size() const;
@@ -201,6 +212,7 @@ class ordered_vector {
201212
bool verify_list_nonunique() const;
202213

203214
INLINE void push_back(const VALUE_TYPE &key);
215+
INLINE void push_back(VALUE_TYPE &&key);
204216
INLINE void pop_back();
205217
INLINE void resize(SIZE_TYPE n);
206218
INLINE void resize(SIZE_TYPE n, const VALUE_TYPE &value);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy