diff options
-rw-r--r-- | common/stack.h | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/common/stack.h b/common/stack.h index ce438b6174..123cacd6cb 100644 --- a/common/stack.h +++ b/common/stack.h @@ -49,23 +49,27 @@ public: assert(_size < MAX_SIZE); _stack[_size++] = x; } - T top() const { - if (_size > 0) - return _stack[_size - 1]; - else - return 0; + const T& top() const { + assert(_size > 0); + return _stack[_size - 1]; } - T pop() { - T tmp; + T& top() { assert(_size > 0); - tmp = _stack[_size - 1]; - _stack[--_size] = 0; + return _stack[_size - 1]; + } + T pop() { + T tmp = top(); + --_size; return tmp; } int size() const { return _size; } - T operator [](int i) { + T& operator [](int i) { + assert(0 <= i && i < MAX_SIZE); + return _stack[i]; + } + const T& operator [](int i) const { assert(0 <= i && i < MAX_SIZE); return _stack[i]; } |