From 1fd8af5acde06e2c3ba54bd8dfa624387c37fd59 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 9 Jul 2017 19:55:29 +0200 Subject: [PATCH] express: add C++11 methods to ordered_vector --- panda/src/express/ordered_vector.I | 98 ++++++++++++++++++++++++++++++ panda/src/express/ordered_vector.h | 12 ++++ 2 files changed, 110 insertions(+) diff --git a/panda/src/express/ordered_vector.I b/panda/src/express/ordered_vector.I index 24a74c6a45..287998b85c 100644 --- a/panda/src/express/ordered_vector.I +++ b/panda/src/express/ordered_vector.I @@ -109,6 +109,44 @@ rend() const { return _vector.rend(); } +/** + * Returns the iterator that marks the first element in the ordered vector. + */ +template +INLINE TYPENAME ordered_vector::CONST_ITERATOR ordered_vector:: +cbegin() const { + return _vector.begin(); +} + +/** + * Returns the iterator that marks the end of the ordered vector. + */ +template +INLINE TYPENAME ordered_vector::CONST_ITERATOR ordered_vector:: +cend() const { + return _vector.end(); +} + +/** + * Returns the iterator that marks the first element in the ordered vector, + * when viewed in reverse order. + */ +template +INLINE TYPENAME ordered_vector::CONST_REVERSE_ITERATOR ordered_vector:: +crbegin() const { + return _vector.rbegin(); +} + +/** + * Returns the iterator that marks the end of the ordered vector, when viewed + * in reverse order. + */ +template +INLINE TYPENAME ordered_vector::CONST_REVERSE_ITERATOR ordered_vector:: +crend() const { + return _vector.rend(); +} + /** * Returns the nth element. */ @@ -127,6 +165,54 @@ operator [] (TYPENAME ordered_vector::SIZE_TYPE n) const { return _vector[n]; } +/** + * Returns a reference to the first element. + */ +template +INLINE TYPENAME ordered_vector::REFERENCE ordered_vector:: +front() { +#ifdef _DEBUG + assert(!_vector.empty()); +#endif + return _vector[0]; +} + +/** + * Returns a const reference to the first element. + */ +template +INLINE TYPENAME ordered_vector::CONST_REFERENCE ordered_vector:: +front() const { +#ifdef _DEBUG + assert(!_vector.empty()); +#endif + return _vector[0]; +} + +/** + * Returns a reference to the first element. + */ +template +INLINE TYPENAME ordered_vector::REFERENCE ordered_vector:: +back() { +#ifdef _DEBUG + assert(!_vector.empty()); +#endif + return _vector[_vector.size() - 1]; +} + +/** + * Returns a const reference to the last element. + */ +template +INLINE TYPENAME ordered_vector::CONST_REFERENCE ordered_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 +INLINE void ordered_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. */ diff --git a/panda/src/express/ordered_vector.h b/panda/src/express/ordered_vector.h index 7eacfc375e..e9e3a03693 100644 --- a/panda/src/express/ordered_vector.h +++ b/panda/src/express/ordered_vector.h @@ -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);