Standard Template Library (STL) - std::queue::pop

Standard Template Library (STL) - std::queue::pop

public member function - 公开成员函数

1. std::queue::pop

void pop();

removes the first element - 删除队列的第一个元素。

Remove next element
删除 queue 中前端的元素。

Removes the next element in the queue, effectively reducing its size by one.
删除 queue 中前端的元素,有效地将其大小减小一个。

The element removed is the oldest element in the queue whose value can be retrieved by calling member queue::front.
删除的元素是 queue 中插入最早的元素,可以通过调用成员 queue::front 来检索其值。

This calls the removed element’s destructor.
这将调用已删除元素的析构函数。

This member function effectively calls the member function pop_front of the underlying container object.
这个成员函数有效地调用底层容器对象的成员函数 pop_front

2. Parameters

none

3. Return value

none

4. Examples

4.1 std::queue::pop

//============================================================================
// Name        : std::queue::push/pop
// Author      : Yongqiang Cheng
// Version     : Version 1.0.0
// Copyright   : Copyright (c) 2019 Yongqiang Cheng
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>       // std::cin, std::cout
#include <queue>          // std::queue

int main()
{
	std::queue<int> queue_data;
	int int_data;

	std::cout << "Please enter some integers (enter 0 to end):\n";

	do
	{
		std::cin >> int_data;
		queue_data.push(int_data);
	} while (int_data);

	std::cout << "queue_data contains: ";
	while (!queue_data.empty())
	{
		std::cout << ' ' << queue_data.front();
		queue_data.pop();
	}
	std::cout << '\n';

	return 0;
}

The example uses push to add a new elements to the queue, which are then popped out in the same order.
该示例使用 push 将新元素添加到队列中,然后以相同顺序弹出。

Please enter some integers (enter 0 to end):
3
6
8
0
queue_data contains:  3 6 8 0

5. Complexity - 复杂度

Constant (calling pop_front on the underlying container).
常量 (在底层容器上调用 pop_front)。

6. Data races - 数据竞争

The container and up to all its contained elements are modified.
容器及其所有包含的元素均已修改。

7. Exception safety - 异常安全性

Provides the same level of guarantees as the operation performed on the underlying container object.
提供与对底层容器对象执行的操作相同级别的保证。

assignment [ə'saɪnmənt]:n. 任务,布置,赋值

References

http://www.cplusplus.com/reference/queue/queue/pop/
https://en.cppreference.com/w/cpp/container/queue/pop

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章