На этом шаге мы приведем реализацию класса queue.
Типичная реализация класса queue<>, как и реализация класса stack<>, не требует особых комментариев:
namespace std {
template <class T, class Container = deque<T> >
class queue {
public:
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef Container container_type;
protected:
Container c; // Контейнер
public:
explicit queue(const Container& = Container());
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
void push(const value_type& x) { c.push_back(x); }
void pop() { c.pop_front(); }
value_type& front() { return c.front(); }
const value_type& front() const { return c.front(); }
value_type& back() { return c.back(); }
const value_type& back() const { return c.back(); }
};
template <class T, class Container>
bool operator==(const queue<T, Container>&,
const queue<T, Container>&);
template <class T, class Container>
bool operator< (const queue<T, Container>&,
const queue<T, Container>&);
... // (Другие операторы сравнения)
}
В следующих шагах приводятся более подробные описания членов класса queue<>.
На следующем шаге мы рассмотрим определение типов в этом классе.