我正在閱讀來自cppreference的std::ignore
文檔。我發現很難理解這個對象的真正目的,而示例代碼並沒有太多公正。例如,在下面的代碼中,爲什麼inserted
設置爲true?這對我來說沒有多大意義。請解釋此代碼使用std :: ignore
#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";
}
}
如果有人可以向我解釋代碼,將不勝感激。謝謝。
你明白'std :: tie'的作用,'std :: set :: insert'返回什麼? – Xymostech 2013-04-26 01:39:09
@Xymostech我知道'tie'是幹什麼的。儘管我沒有想到「插入」。 – 2013-04-26 01:40:12
'bool inserted = std :: get <1>(set_of_str。insert(「Test」));' – bames53 2013-04-26 15:15:14