function template (函数模板)
<utility>
std::get (pair)
lvalue (1) (左值 (1)) | template <size_t I, class T1, class T2> typename tuple_element< I, pair<T1,T2> >::type& get (pair<T1,T2>& pr) noexcept; |
---|
rvalue (2) (右值 (2)) | template <size_t I, class T1, class T2> typename tuple_element< I, pair<T1,T2> >::type&& get (pair<T1,T2>&& pr) noexcept; |
---|
const (3) (常量 (3)) | template <size_t I, class T1, class T2> const typename tuple_element< I, pair<T1,T2> >::type& get (const pair<T1,T2>& pr) noexcept; |
---|
Get element (tuple interface) (获取元素 (元组接口))
模板参数
- I (索引)
- Position of an element in the pair, with
0
identifying member first, and 1
identifying member second. ( pair 中元素的位置,0
表示成员 first,1
表示成员 second。)
size_t 是一个无符号整数类型。
- T1, T2
- pair 中元素的类型。
Function parameters (函数参数)
- pr
- A pair object. (一个 pair 对象。)
返回值
A reference to a member of the pair. (对 pair 的成员的引用。)
For rvalue pair objects (2), the function returns an rvalue reference (as if forward was used). (对于 右值 pair 对象 (2),该函数返回一个 右值引用 (就像使用了 forward 一样)。)
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// accessing pairs with get
#include <utility> // std::pair, std::get
#include <iostream> // std::cout
int main () {
std::pair <int,char> foo (10,'x');
std::get<0>(foo) = 50;
std::cout << "foo contains: ";
std::cout << std::get<0>(foo) << " and " << std::get<1>(foo) << '\n';
return 0;
}
|
输出
数据竞争
One of the members of pr is potentially accessed or modified by the caller. Concurrently accessing the other is safe. (调用者可能会访问或修改 pr 的其中一个成员。并发访问另一个成员是安全的。)