I got following code that intends to extract value from map of pointers, modified pointed object and insert it back. But inserting does not work.
struct A{
std::string name;
mutable uint64_t s;
mutable uint64_t b;
bool operator<(const A& a)const {
return name < a.name;
}
};
struct classcomp
{
bool operator ()(const A* lhs, const A* rhs) const {
return A->s > A->s;
}
};
...
std::set<struct A*, classcomp> largestS;
...
auto myS = largestS.extract(largestS.begin());
myS.value()->s -=20;
largestS.insert(std::move(myS));
What am I doing wrong. I use Visual Studio 2022 and C++ 17.