How well do you know tie
and ignore
, especially to use the C++11 multiple return value idiom?
Please explain this code that uses std::ignore
I'm reading the documentation on
std::ignore
from cppreference. I find it quite hard to grasp the true purpose of this object, and the example code doesn't do it much justice. For example, in the below code, how and why isinserted
set to true? It doesn't make much sense to me.#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"; } }If someone can explain the code to me, it would be appreciated. Thanks.
Add a Comment
Comments are closed.