diff options
author | Martin Liska <mliska@suse.cz> | 2018-05-29 11:55:02 +0200 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2018-05-29 09:55:02 +0000 |
commit | c04f64807ee5e911741290aafc90d17618a02dca (patch) | |
tree | edf1890fb08bd388e0654ec0a86b1dfadec70166 /gcc/vec.h | |
parent | 86e74d5869813c22b946d76e7dbe960ef0a0c1f2 (diff) | |
download | gcc-c04f64807ee5e911741290aafc90d17618a02dca.zip gcc-c04f64807ee5e911741290aafc90d17618a02dca.tar.gz gcc-c04f64807ee5e911741290aafc90d17618a02dca.tar.bz2 |
Add vec::reverse.
2018-05-29 Martin Liska <mliska@suse.cz>
David Malcolm <dmalcolm@redhat.com>
* vec.c (test_reverse): New.
(vec_c_tests): Add new test.
* vec.h (vl_ptr>::reverse): New function.
Co-Authored-By: David Malcolm <dmalcolm@redhat.com>
From-SVN: r260890
Diffstat (limited to 'gcc/vec.h')
-rw-r--r-- | gcc/vec.h | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -1389,6 +1389,7 @@ public: T *bsearch (const void *key, int (*compar)(const void *, const void *)); unsigned lower_bound (T, bool (*)(const T &, const T &)) const; bool contains (const T &search) const; + void reverse (void); bool using_auto_storage () const; @@ -1900,6 +1901,19 @@ vec<T, va_heap, vl_ptr>::contains (const T &search) const return m_vec ? m_vec->contains (search) : false; } +/* Reverse content of the vector. */ + +template<typename T> +inline void +vec<T, va_heap, vl_ptr>::reverse (void) +{ + unsigned l = length (); + T *ptr = address (); + + for (unsigned i = 0; i < l / 2; i++) + std::swap (ptr[i], ptr[l - i - 1]); +} + template<typename T> inline bool vec<T, va_heap, vl_ptr>::using_auto_storage () const |