26 Containers library [containers]

26.6 Container adaptors [container.adaptors]

26.6.4 Class template queue [queue]

26.6.4.1 queue definition [queue.defn]

Any sequence container supporting operations front(), back(), push_­back() and pop_­front() can be used to instantiate queue. In particular, list and deque can be used.

namespace std {
  template <class T, class Container = deque<T>>
  class queue {
  public:
    using value_type      = typename Container::value_type;
    using reference       = typename Container::reference;
    using const_reference = typename Container::const_reference;
    using size_type       = typename Container::size_type;
    using container_type  =          Container;

  protected:
    Container c;

  public:
    explicit queue(const Container&);
    explicit queue(Container&& = Container());
    template <class Alloc> explicit queue(const Alloc&);
    template <class Alloc> queue(const Container&, const Alloc&);
    template <class Alloc> queue(Container&&, const Alloc&);
    template <class Alloc> queue(const queue&, const Alloc&);
    template <class Alloc> queue(queue&&, const Alloc&);

    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 push(value_type&& x)           { c.push_back(std::move(x)); }
    template <class... Args>
      reference emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }
    void pop()                          { c.pop_front(); }
    void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
      { using std::swap; swap(c, q.c); }
  };

  template<class Container>
    queue(Container) -> queue<typename Container::value_type, Container>;

  template<class Container, class Allocator>
    queue(Container, Allocator) -> queue<typename Container::value_type, Container>;

  template <class T, class Container>
    bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);
  template <class T, class Container>
    bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);
  template <class T, class Container>
    bool operator!=(const queue<T, Container>& x, const queue<T, Container>& y);
  template <class T, class Container>
    bool operator> (const queue<T, Container>& x, const queue<T, Container>& y);
  template <class T, class Container>
    bool operator>=(const queue<T, Container>& x, const queue<T, Container>& y);
  template <class T, class Container>
    bool operator<=(const queue<T, Container>& x, const queue<T, Container>& y);

  template <class T, class Container>
    void swap(queue<T, Container>& x, queue<T, Container>& y) noexcept(noexcept(x.swap(y)));

  template <class T, class Container, class Alloc>
    struct uses_allocator<queue<T, Container>, Alloc>
      : uses_allocator<Container, Alloc>::type { };
}

26.6.4.2 queue constructors [queue.cons]

explicit queue(const Container& cont);

Effects:  Initializes c with cont.

explicit queue(Container&& cont = Container());

Effects:  Initializes c with std​::​move(cont).

26.6.4.3 queue constructors with allocators [queue.cons.alloc]

If uses_­allocator_­v<container_­type, Alloc> is false the constructors in this subclause shall not participate in overload resolution.

template <class Alloc> explicit queue(const Alloc& a);

Effects:  Initializes c with a.

template <class Alloc> queue(const container_type& cont, const Alloc& a);

Effects:  Initializes c with cont as the first argument and a as the second argument.

template <class Alloc> queue(container_type&& cont, const Alloc& a);

Effects:  Initializes c with std​::​move(cont) as the first argument and a as the second argument.

template <class Alloc> queue(const queue& q, const Alloc& a);

Effects:  Initializes c with q.c as the first argument and a as the second argument.

template <class Alloc> queue(queue&& q, const Alloc& a);

Effects:  Initializes c with std​::​move(q.c) as the first argument and a as the second argument.

26.6.4.4 queue operators [queue.ops]

template <class T, class Container> bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);

Returns: x.c == y.c.

template <class T, class Container> bool operator!=(const queue<T, Container>& x, const queue<T, Container>& y);

Returns: x.c != y.c.

template <class T, class Container> bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);

Returns: x.c < y.c.

template <class T, class Container> bool operator<=(const queue<T, Container>& x, const queue<T, Container>& y);

Returns: x.c <= y.c.

template <class T, class Container> bool operator> (const queue<T, Container>& x, const queue<T, Container>& y);

Returns: x.c > y.c.

template <class T, class Container> bool operator>=(const queue<T, Container>& x, const queue<T, Container>& y);

Returns: x.c >= y.c.

26.6.4.5 queue specialized algorithms [queue.special]

template <class T, class Container> void swap(queue<T, Container>& x, queue<T, Container>& y) noexcept(noexcept(x.swap(y)));

Remarks: This function shall not participate in overload resolution unless is_­swappable_­v<Container> is true.

Effects: As if by x.swap(y).