I have a self defined struct, which i overload the operator >:
struct A {
A(int a) : a_(a) {}
int a_;
friend operator > (const A& a) const {
return a_ > a.a_;
}
};
so i can push this struct into stl container set:
std::set<A> s;
s.insert(A(3));
s.insert(A(5));
s.insert(A(4));
but i am doing a large task, which means, copy operation is costly for me.
So, i want to build a set with element type of pointer like this:
std::set<A*>s;
A a(3); A b(5); A c(4);
s.insert(&a); s.insert(&b); s.insert(&c);
but i found it failed to keep the order, is there any methods that can keep the order by element pointer?
or, how can i save element in a ordered container, without copying and have good performance?