From: wessels <> Date: Tue, 22 Nov 2005 05:43:41 +0000 (+0000) Subject: Added Vector::shift() method, similar to the way shift works in Perl. X-Git-Tag: SQUID_3_0_PRE4~522 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d522003d1df1915babc26d7ac89013cdb6ff7592;p=thirdparty%2Fsquid.git Added Vector::shift() method, similar to the way shift works in Perl. This was done for ICAP integration. --- diff --git a/include/Array.h b/include/Array.h index 10bf25cc3a..93b7f89357 100644 --- a/include/Array.h +++ b/include/Array.h @@ -1,5 +1,5 @@ /* - * $Id: Array.h,v 1.23 2005/08/03 15:38:23 hno Exp $ + * $Id: Array.h,v 1.24 2005/11/21 22:43:41 wessels Exp $ * * AUTHOR: Alex Rousskov * @@ -93,9 +93,11 @@ public: void reserve (size_t capacity); void push_back (E); Vector &operator += (E item) {push_back(item); return *this;}; + void insert (E); E &back(); E pop_back(); + E shift(); // aka pop_front void preAppend(int app_count); bool empty() const; size_t size() const; @@ -199,13 +201,30 @@ Vector::insert(E obj) reserve (size() + 1); int i; + for (i = count; i > 0; i--) items[i] = items[i - 1]; items[i] = obj; + count += 1; } +template +E +Vector::shift() +{ + assert (size()); + value_type result = items[0]; + + for (unsigned int i = 1; i < count; i++) + items[i-1] = items[i]; + + count--; + + return result; +} + template E Vector::pop_back()