Standard Template Library (STL) - std::queue::back
Standard Template Library (STL) - std::queue::back
std::queue::back
public member function - 公开成员函数
1. std::queue::back
C++98value_type& back();
const value_type& back() const;
C++11reference& back();
const_reference& back() const;
返回到 queue
中末元素的引用。这是最近推入的元素。
Access last element - 访问最后一个元素
Returns a reference to the last element in the queue. This is the newest element in the queue (i.e. the last element pushed into the queue).
返回对队列中最后一个元素的引用。这是队列中的最新元素 (即,最后一个被推入队列的元素)。
This member function effectively calls member back of the underlying container object.
该成员函数有效地调用底层容器对象的成员 back
。
2. Parameters
none
3. Return value
A reference to the last element in the queue
.
对 queue
中最后一个元素的引用。
C++98
Member type value_type
is the type of the elements in the container (defined as an alias of the first class template parameter, T
).
成员类型 value_type
是容器中元素的类型 (定义为第一类模板参数 T
的别名)。
C++11
Member types reference
and const_reference
are aliases of the underlying container’s types with the same name.
成员类型 reference
and const_reference
是具有相同名称的底层容器类型的别名。
4. Examples
4.1 std::queue::front
//============================================================================
// Name : std::queue::back
// Author : Yongqiang Cheng
// Version : Version 1.0.0
// Copyright : Copyright (c) 2019 Yongqiang Cheng
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream> // std::cout
#include <queue> // std::queue
int main()
{
std::queue<int> queue_data;
queue_data.push(12);
queue_data.push(75); // this is now the back
queue_data.back() -= queue_data.front();
std::cout << "queue_data.back() is now " << queue_data.back() << '\n';
return 0;
}
queue_data.back() is now 63
5. Complexity - 复杂度
Constant (calling back
on the underlying container).
常量 (在底层容器上调用 back
)。
6. Data races - 数据竞争
The container is accessed (neither the const nor the non-const versions modify the container).
容器被访问 (const 和非 const 版本都不能修改容器)。
The reference returned can be used to access or modify the last element.
返回的引用可用于访问或修改最后一个元素。
7. Exception safety - 异常安全性
Provides the same level of guarantees as the operation performed on the container (no-throw guarantee for standard non-empty containers).
提供与在容器上执行的操作相同级别的保证 (对于标准非空容器,无抛出保证)。
assignment [ə'saɪnmənt]:n. 任务,布置,赋值
References
http://www.cplusplus.com/reference/queue/queue/back/
https://en.cppreference.com/w/cpp/container/queue/back