diff --git a/src/sfall_arrays.cc b/src/sfall_arrays.cc index 8d72371..f135130 100644 --- a/src/sfall_arrays.cc +++ b/src/sfall_arrays.cc @@ -389,9 +389,13 @@ void SFallArrayAssoc::MapSort(int type) if (sortByValue) { ListSort(keys, type, [this](const ArrayElement& a, const ArrayElement& b) -> bool { - auto& aEl = this->map[a]; - auto& bEl = this->map[b]; - return aEl < bEl; + // Why return this->map[a] < this->map[b] does not work? Why it requires copy constructor? + auto itA = this->map.find(a); + auto itB = this->map.find(a); + if (itA == map.end() || itB == map.end()) { + throw(std::exception()); + }; + return itA->second < itB->second; }); } else { ListSort(keys, type, std::less());