express: add C++11 methods to ordered_vector

This commit is contained in:
rdb 2017-07-09 19:55:29 +02:00
parent 84520ce21c
commit 1fd8af5acd
2 changed files with 110 additions and 0 deletions

View File

@ -109,6 +109,44 @@ rend() const {
return _vector.rend();
}
/**
* Returns the iterator that marks the first element in the ordered vector.
*/
template<class Key, class Compare, class Vector>
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_ITERATOR ordered_vector<Key, Compare, Vector>::
cbegin() const {
return _vector.begin();
}
/**
* Returns the iterator that marks the end of the ordered vector.
*/
template<class Key, class Compare, class Vector>
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_ITERATOR ordered_vector<Key, Compare, Vector>::
cend() const {
return _vector.end();
}
/**
* Returns the iterator that marks the first element in the ordered vector,
* when viewed in reverse order.
*/
template<class Key, class Compare, class Vector>
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_REVERSE_ITERATOR ordered_vector<Key, Compare, Vector>::
crbegin() const {
return _vector.rbegin();
}
/**
* Returns the iterator that marks the end of the ordered vector, when viewed
* in reverse order.
*/
template<class Key, class Compare, class Vector>
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_REVERSE_ITERATOR ordered_vector<Key, Compare, Vector>::
crend() const {
return _vector.rend();
}
/**
* Returns the nth element.
*/
@ -127,6 +165,54 @@ operator [] (TYPENAME ordered_vector<Key, Compare, Vector>::SIZE_TYPE n) const {
return _vector[n];
}
/**
* Returns a reference to the first element.
*/
template<class Key, class Compare, class Vector>
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::REFERENCE ordered_vector<Key, Compare, Vector>::
front() {
#ifdef _DEBUG
assert(!_vector.empty());
#endif
return _vector[0];
}
/**
* Returns a const reference to the first element.
*/
template<class Key, class Compare, class Vector>
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_REFERENCE ordered_vector<Key, Compare, Vector>::
front() const {
#ifdef _DEBUG
assert(!_vector.empty());
#endif
return _vector[0];
}
/**
* Returns a reference to the first element.
*/
template<class Key, class Compare, class Vector>
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::REFERENCE ordered_vector<Key, Compare, Vector>::
back() {
#ifdef _DEBUG
assert(!_vector.empty());
#endif
return _vector[_vector.size() - 1];
}
/**
* Returns a const reference to the last element.
*/
template<class Key, class Compare, class Vector>
INLINE TYPENAME ordered_vector<Key, Compare, Vector>::CONST_REFERENCE ordered_vector<Key, Compare, Vector>::
back() const {
#ifdef _DEBUG
assert(!_vector.empty());
#endif
return _vector[_vector.size() - 1];
}
/**
* Returns the number of elements in the ordered vector.
*/
@ -530,6 +616,18 @@ push_back(const value_type &key) {
_vector.push_back(key);
}
/**
* Adds the new element to the end of the vector without regard for proper
* sorting. This is a bad idea to do except to populate the vector the first
* time; be sure to call sort() after you have added all the elements.
*/
template<class Key, class Compare, class Vector>
INLINE void ordered_vector<Key, Compare, Vector>::
push_back(value_type &&key) {
TAU_PROFILE("ordered_vector::push_back()", " ", TAU_USER);
_vector.push_back(move(key));
}
/**
* Removes the last element at the end of the vector.
*/

View File

@ -147,10 +147,21 @@ public:
INLINE CONST_REVERSE_ITERATOR rbegin() const;
INLINE CONST_REVERSE_ITERATOR rend() const;
INLINE CONST_ITERATOR cbegin() const;
INLINE CONST_ITERATOR cend() const;
INLINE CONST_REVERSE_ITERATOR crbegin() const;
INLINE CONST_REVERSE_ITERATOR crend() const;
// Random access.
INLINE reference operator [] (SIZE_TYPE n);
INLINE const_reference operator [] (SIZE_TYPE n) const;
INLINE reference front();
INLINE const_reference front() const;
INLINE reference back();
INLINE const_reference back() const;
// Size information.
INLINE SIZE_TYPE size() const;
INLINE SIZE_TYPE max_size() const;
@ -201,6 +212,7 @@ public:
bool verify_list_nonunique() const;
INLINE void push_back(const VALUE_TYPE &key);
INLINE void push_back(VALUE_TYPE &&key);
INLINE void pop_back();
INLINE void resize(SIZE_TYPE n);
INLINE void resize(SIZE_TYPE n, const VALUE_TYPE &value);