I created a structure ready to receive iterators from diferent associative containers (set, map, multiset etc) and keep a pointer to this element.
set<ObjX> SetX {...}
set<ObjY> SetY {...}
map<ObjZ, Data> MapZ {...}
struct INPosition {
INPosition(set<ObjX>::const_iterator pTMP) : POINTER(&*pTMP) {}
INPosition(set<ObjY>::const_iterator pTMP) : POINTER(&*pTMP) {}
INPosition(map<ObjZ, Data>::const_iterator pTMP) : POINTER(&*pTMP) {}
void show() { cout << POINTER << '\t' << typeid(POINTER).name() << '\n'; }
private:
const void* POINTER;
};
INPosition TTT(SetY.find(ObjY(2)));
cout << "Addr SetY Element 1: " << &*SetY.find(1) << '\t'<< typeid(&*SetY.find(1)).name() << '\n';
cout << "Addr SetY Element 2: " << &*SetY.find(2) << '\t'<< typeid(&*SetY.find(2)).name() << '\n';
cout << "Addr POINTER (Elm 2): "; TTT.show();
The result are:
Addr SetY Element 1: 0x5654ee2096d0 PKSt10ObjYI10MyClassSt14default_deleteIS0_EE
Addr SetY Element 2: 0x5654ee209720 PKSt10ObjYI10MyClassSt14default_deleteIS0_EE
Addr POINTER (Elm 2): 0x5654ee209720 PKv //The typeid.name supposes to be the same than Element 2 above???
POINTER keep the element address, but typeid doesn't recognize this element I supposed to (Same as element 2).
My question is how can create a function member that return the casted with the correct type? In other words, recover the iterator. Something like this:
auto Iterator() {
return auto_cast(POINTER);
}