How do I make a set where the elements are always ordered using some local variable?
A simplified example of what I am trying to do is this.
int x[5] {9, 2, 3, 1, 8};
set<int, ???> my_set;
my_set.insert(0);
my_set.insert(1);
my_set.insert(4);
for (int a : my_set)
cout << a << " "; // I want the answer 1 4 0 because x[1] < x[4] < x[0]
I think I might be able to do this using a struct
, but I am unsure how the use of x
changes things.