queue::queue
描述 (Description)
C ++移动构造函数std::queue::queue()使用移动语义构造具有其他内容的容器。
声明 (Declaration)
以下是移动构造函数std :: queue :: queue()形式std :: queue头的声明。
C++11
queue( queue&& other);
参数 (Parameters)
other - 相同类型的另一个队列对象。
返回值
构造函数永远不会返回值
异常 (Exceptions)
该成员函数从不抛出异常。
时间复杂
线性即O(n)
例子 (Example)
以下示例显示了std :: queue :: queue()函数的用法。
#include <iostream>
#include <queue>
#include <list>
using namespace std;
int main(void) {
auto it = {1, 2, 3, 4, 5};
queue<int> q1(it);
queue<int>q2(move(q1));
cout << "Contents of q1 after move operation" << endl;
while (!q1.empty()) {
cout << q1.front() << endl;
q1.pop();
}
cout << endl << endl;
cout << "Contents of q2 after move operation" << endl;
while (!q2.empty()) {
cout << q2.front() << endl;
q2.pop();
}
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Contents of q1 after move operation
Contents of q2 after move operation
1
2
3
4
5