rayzor

diff src/stl/vector.h @ 9:70e332156d02

moving along
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 10 Apr 2014 02:31:31 +0300
parents 18bdbcbaee81
children d94a69933a71
line diff
     1.1 --- a/src/stl/vector.h	Mon Apr 07 08:46:06 2014 +0300
     1.2 +++ b/src/stl/vector.h	Thu Apr 10 02:31:31 2014 +0300
     1.3 @@ -47,6 +47,7 @@
     1.4  	void clear()
     1.5  	{
     1.6  		delete [] data;
     1.7 +		data = 0;
     1.8  		max_items = num_items = 0;
     1.9  	}
    1.10  
    1.11 @@ -89,6 +90,27 @@
    1.12  		data[num_items++] = item;
    1.13  	}
    1.14  
    1.15 +	void pop_back()
    1.16 +	{
    1.17 +		if(--num_items <= 0) {
    1.18 +			num_items = 0;
    1.19 +		}
    1.20 +
    1.21 +		if(num_items < max_items / 3) {
    1.22 +			resize(max_items / 2);
    1.23 +		}
    1.24 +	}
    1.25 +
    1.26 +	T &back()
    1.27 +	{
    1.28 +		return data[num_items - 1];
    1.29 +	}
    1.30 +
    1.31 +	const T &back() const
    1.32 +	{
    1.33 +		return data[num_items - 1];
    1.34 +	}
    1.35 +
    1.36  	T &operator [](int idx)
    1.37  	{
    1.38  		return data[idx];