Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

queue::queue

公众成员函数  <queue>

C++98;
explicit queue (const container_type& ctnr = container_type());
C++11; initialize (1)
explicit queue (const container_type& ctnr);
move-initialize (2)
explicit queue (container_type&& ctnr = container_type());
allocator (3)
template <class Alloc> explicit queue (const Alloc& alloc);
init + allocator (4)
template <class Alloc> queue (const container_type& ctnr, const Alloc& alloc);
move-init + allocator (5)
template <class Alloc> queue (container_type&& ctnr, const Alloc& alloc);
copy + allocator (6)
template <class Alloc> queue (const queue& x, const Alloc& alloc);
move + allocator (7)
template <class Alloc> queue (queue&& x, const Alloc& alloc);

构建队列

构造一个队列容器适配器对象:

C++98:
容器适配器在内部将容器对象保存为数据。 该容器对象是传递给构造函数的ctnr参数的副本(如果有的话),否则它是一个空容器。

☲  参数


ctnr
容器对象。
container_type是底层容器类型的类型(定义为第二个类模板形参container的别名;见成员类型)。
alloc
分配器对象。
Alloc必须是uses_allocator::value为true的类型(对于其他类型,构造函数甚至不参与重载解析)。
x
相同类型的队列(即具有相同模板参数,T和Container)。

☣  示例



// constructing queues
#include <iostream>       // std::cout
#include <deque>          // std::deque
#include <list>           // std::list
#include <queue>          // std::queue

int main ()
{
  std::deque<int> mydeck (3,100);        // deque with 3 elements
  std::list<int> mylist (2,200);         // list with 2 elements

  std::queue<int> first;                 // empty queue
  std::queue<int> second (mydeck);       // queue initialized to copy of deque

  std::queue<int,std::list<int> > third; // empty queue with list as underlying container
  std::queue<int,std::list<int> > fourth (mylist);

  std::cout << "size of first: " << first.size() << '\n';
  std::cout << "size of second: " << second.size() << '\n';
  std::cout << "size of third: " << third.size() << '\n';
  std::cout << "size of fourth: " << fourth.size() << '\n';

  return 0;
}

输出:
size of first: 0
size of second: 3
size of third: 0
size of fourth: 2

✥ 复杂度



一个容器构造(对于标准容器而言,其大小达到线性)。

☣ 迭代器的有效性



移动构造函数(2)和(7)可能使所有与moved实参相关的迭代器、指针和引用失效。

⇄ 数据竞争


访问所有复制的元素。动构造函数(2)和(7)可能修改它们的(第一个)参数。

☂ 异常安全性



提供与在容器上执行的操作相同级别的保证。

🍄  另请参阅



queue::push 插入元素(公众成员函数)

联系我们 免责声明 关于CandCplus 网站地图