std::ignore
来自cppreference.com
![]() |
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <tuple> 中定义
|
||
const /*unspecified*/ ignore; |
(C++11 起) | |
对象的类型不明确,使得任何价值。它可以被分配到没有任何影响。拟使用std::tie一个std::tuple打开包装时,如果一个类型是有符号的算术类型的占位符的参数不使用
原文:
An object of unspecified type such that any value can be assigned to it with no effect. Intended for use with std::tie when unpacking a std::tuple, as a placeholder for the arguments that are not used.
[编辑] 示例
解包由set.insert()返回一对,但只有保存布尔.
原文:
unpack a pair returned by set.insert(), but only save the boolean.
#include <iostream> #include <string> #include <set> #include <tuple> int main() { std::set<std::string> set_of_str; bool inserted; std::tie(std::ignore, inserted) = set_of_str.insert("Test"); if (inserted) { std::cout << "Value was inserted sucessfully\n"; } }
输出:
Value was inserted sucessfully
创建一个tuple 的左值引用或将一个元组拆开成多个个体对象 (函数模板) |