tuple::operator=
描述 (Description)
它是一个元组运算符,并将tpl(或pr)指定为元组对象的新内容。
声明 (Declaration)
以下是std :: tuple :: operator =的声明
C++98
tuple& operator= (const tuple& tpl);
tuple& operator= ( tuple&& tpl) noexcept
C++11
tuple& operator= (const tuple& tpl);
tuple& operator= ( tuple&& tpl) noexcept
参数 (Parameters)
tpl - 它是另一个具有相同元素数的元组对象。
pr - 它有一对对象。
返回值 (Return Value)
没有
异常 (Exceptions)
No-throw guarantee - 此成员函数永远不会抛出异常。
数据竞争 (Data races)
访问所有复制的元素。
例子 (Example)
在下面的示例中,std :: tuple :: operator =。
#include <iostream>
#include <utility>
#include <tuple>
int main () {
std::pair<int,char> mypair (0,' ');
std::tuple<int,char> a (10,'x');
std::tuple<long,char> b, c;
b = a;
c = std::make_tuple (100L,'Y');
a = c;
c = std::make_tuple (100,'z');
a = mypair;
a = std::make_pair (2,'b');
std::cout << "a contains: " << std::get<0>(a);
std::cout << " and " << std::get<1>(a) << '\n';
return 0;
}
输出应该是这样的 -
a contains: 2 and b