template<class T> struct const_ptr_compare:std::less<T const*> { typedef void is_transparent; }; std::set<AType*, const_ptr_compare<AType>> values;
and Bob is your uncle.
I have defined a comparator that can transparently handle T const* comparisons as well as T* comparisons. Then I told std::set that it is transparent.
The is_transparent method is an upgrade from C ++ 14 to std::set . Your compiler may have support.
If you want to go to base-classes-of- T , a little more work is required. You need a function object that checks its two arguments (each points to const) to see what is the base class of the other, and uses std::less<base const*>{}(lhs, rhs) this base class. However, this goes further down the rabbit hole than we need.
The C ++ 11/03 approach may include creating editable parts of AType mutable and having const AType* set . Otherwise, a const_cast<AType*> is reasonable.
Please do not use the C-style: they are almost never required, and they can be too powerful.
source share