11 #include <Sawyer/Assert.h>
12 #include <Sawyer/Sawyer.h>
27 std::vector<T> vector_;
33 template<
class Iterator>
34 Stack(
const boost::iterator_range<Iterator> &range) {
35 for (Iterator iter=range.begin(); iter!=range.end(); ++iter)
36 vector_.push_back(*iter);
43 return vector_.size();
50 return vector_.empty();
60 return vector_.back();
62 const Value&
top()
const {
64 return vector_.back();
74 Value&
get(
size_t idx) {
75 ASSERT_require(idx <
size());
76 return vector_[vector_.size() - (idx+1)];
78 const Value&
get(
size_t idx)
const {
79 ASSERT_require(idx <
size());
80 return vector_[vector_.size() - (idx+1)];
83 const Value&
operator[](
size_t idx)
const {
return get(idx); }
91 vector_.push_back(value);
Stack(const boost::iterator_range< Iterator > &range)
Construct a stack from an iterator range.
Name space for the entire library.
Stack & push(const Value &value)
Push new item onto stack.
Stack()
Construct an empty stack.
size_t size() const
Returns the number of items on the stack.
Value & operator[](size_t idx)
Access an item not at the top of the stack.
Value pop()
Pop existing item from stack.
const Value & top() const
Returns the top item.
const Value & operator[](size_t idx) const
Access an item not at the top of the stack.
bool isEmpty() const
Determines if the stack is empty.
Value & top()
Returns the top item.