std::tuple은 lexicographical comparison을 지원한다.(boost::tuple도 마찬가지)
Example
#include <iostream> #include <string> #include <set> #include <tuple> struct S { int n; std::string s; float d; bool operator<(const S& rhs) const { // compares n to rhs.n, // then s to rhs.s, // then 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"; }
'programming > C++' 카테고리의 다른 글
Explicit conversion (0) | 2013.02.19 |
---|---|
Online C++ compilers (0) | 2013.02.18 |
std::atomic (0) | 2013.02.18 |
C++11 cheat sheet (0) | 2013.02.18 |
Universal reference (0) | 2013.02.18 |