// C++ program to demonstrate the
// implementation of set of tuples
// by using custom comparator
#include <bits/stdc++.h>
using namespace std;
// Comparator for arranging elements
// in non-ascending order We can
// always modify the comparator as
// per the requirement
struct cmp
{
bool operator()(const tuple<int, int,
int>& x,
const tuple<int, int,
int>& y)
{
if (get<0>(x) == get<0>(y))
{
if (get<1>(x) == get<1>(y))
return get<2>(x) > get<2>(y);
return get<1>(x) > get<1>(y);
}
return get<0>(x) > get<0>(y);
}
};
// Function to print set elements
void print(set<tuple<int, int,
int>, cmp>& setOfTuples)
{
for (auto x : setOfTuples)
{
tuple<int, int, int> tp = x;
cout << get<0>(tp) <<
' ' << get<1>(tp) <<
' ' << get<2>(tp) << '\n';
}
}
// Driver code
int main()
{
// Declaring a set of tuples
set<tuple<int, int,
int>, cmp> setOfTuples;
// Initializing tuples
tuple<int, int,
int> tuple1;
tuple1 = make_tuple(1, 2, 3);
tuple<int, int,
int> tuple2;
tuple2 = make_tuple(2, 3, 5);
tuple<int, int,
int> tuple3;
tuple3 = make_tuple(2, 3, 4);
tuple<int, int,
int> tuple4;
tuple4 = make_tuple(2, 1, 4);
tuple<int, int,
int> tuple5;
tuple5 = make_tuple(5, 8, 14);
// Inserting into set
setOfTuples.insert(tuple1);
setOfTuples.insert(tuple2);
setOfTuples.insert(tuple3);
setOfTuples.insert(tuple4);
setOfTuples.insert(tuple5);
// Calling print function
print(setOfTuples);
return 0;
}