#include <iostream>
#include <string>
#include <set>
#include <tuple>
struct S {
int n;
std::string s;
float d;
bool operator<(const S& rhs) const
{
// n < rhs.n , s to rhs.s, d to rhs.d
return std::tie(n, s, d) < std::tie(rhs.n, rhs.s, rhs.d);
}
};
int main()
{
std::set<S> set_of_s; // S is LessThanComparable
S value{42, "Test", 3.14};
std::set<S>::iterator iter;
bool inserted;
// unpacks the return value of insert into iter and inserted
std::tie(iter, inserted) = set_of_s.insert(value);
if (inserted)
std::cout << "Value was inserted successfully\n";
auto t = std::make_tuple(1, 2, 3);
int x, y, z;
std::tie(x, y, z) = t;
std::cout << x << ' ' << y << ' ' << z << '\n'; //1 2 3
x = y = z = 0;
std::tie(x, y, std::ignore) = t;
std::cout << x << ' ' << y << ' ' << z << '\n'; //1 2 0
return 0;
}
This is personal diary for study documents.
Please comment if I'm wrong or missing something else 😄.
댓글남기기