STL源码阅读(五) (SGI STL v3.3)
stl_stack.h (<stack>)
template <class _Tp, class _Sequence = std::deque<_Tp>>
class stack {
_Sequence c;
...
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
reference top() { return c.back(); }
const_reference top() const { return c.back(); }
void push(const value_type& __x) { c.push_back(__x); }
void pop() { c.pop_back(); }
...
}
stl_queue.h (<queue>)
template <class _Tp, class _Sequence = std::deque<_Tp>>
class queue {
_Sequence c;
...
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
reference front() { return c.front(); }
const_reference front() const { return c.front(); }
reference back() { return c.back(); }
const_reference back() const { return c.back(); }
void push(const value_type& __x) { c.push_back(__x); }
void pop() { c.pop_front(); }
...
}
template <class _Tp,
class _Sequence __STL_DEPENDENT_DEFAULT_TMPL(vector<_Tp>),
class _Compare
__STL_DEPENDENT_DEFAULT_TMPL(less<typename _Sequence::value_type>) > {
_Sequence c;
_Compare comp;
...
priority_queue(const _Compare& __x, const _Sequence& __s)
: c(__s), comp(__x)
{ make_heap(c.begin(), c.end(), comp); }
...
}
参考资料
- sgi STL
- cppreference.com