mardi 28 avril 2020

Storing the iterator of a set to user-defined type in a std::deque in C++

I have a std::set of user-defined type which contains sorted-values based on some criteria[overloaded < operator]. I want to store the iterator from this set into a std::deque which I can use later to update/delete entries from set. Here's what I am doing :

.h file

static std::set<SpanStruct_X> spanXRange;
std::map<uint16_t, std::deque<SpanStruct_X>::iterator> mMap;

.cpp

SpanStruct_X sX;
spanXRange.insert(sX);
mMap[id].push_back(spanXRange.find(sX));

I assume ::iterator is available only for std types and not for user defined and hence I get this compilation error.

Compilation Error :

error: ‘std::map<short unsigned int, std::_Deque_iterator<SpanStruct_X, SpanStruct_X&, SpanStruct_X*> >::mapped_type’ has no member named ‘push_back’
                         mMap[id].push_back(spanXRange.find(sX));

How should I get this done?

Thanks!

Aucun commentaire:

Enregistrer un commentaire