From 5ab15783e2d743d432ac951bf8458fa28d57f6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 13 Feb 2020 15:04:02 +0100 Subject: [PATCH] Fix operator==() of UDQFunctionTable. --- .../Schedule/UDQ/UDQFunctionTable.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp index 8085fdd8e..8723f5d7c 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -132,9 +133,19 @@ bool UDQFunctionTable::operator==(const UDQFunctionTable& data) const { if (this->functionMap().size() != data.functionMap().size()) return false; - auto tIt = this->functionMap().begin(); - auto dIt = data.functionMap().begin(); - for (; tIt != this->functionMap().end(); ++tIt, ++dIt) { + // Simply using the operator== method of std::unordered_map would + // compare the pointers contained and not the objects pointed to. + // We therefore must iterate manually through the container. The + // order of the map elements does not matter, and is + // indeterminate. Sorting must be done before comparision so that + // we compare elements with the same key to each other. + using SortedMap = std::map>; + SortedMap sorted_fmap(this->functionMap().begin(), this->functionMap().end()); + SortedMap data_sorted_fmap(data.functionMap().begin(), data.functionMap().end()); + + auto tIt = sorted_fmap.begin(); + auto dIt = data_sorted_fmap.begin(); + for (; tIt != sorted_fmap.end(); ++tIt, ++dIt) { if (tIt->first != dIt->first) return false;