diff --git a/include/osmium/osm/object_comparisons.hpp b/include/osmium/osm/object_comparisons.hpp index 96a5ca7e..a24e53d2 100644 --- a/include/osmium/osm/object_comparisons.hpp +++ b/include/osmium/osm/object_comparisons.hpp @@ -154,17 +154,17 @@ namespace osmium { * (negative IDs first, then positive IDs, both in the order of their * absolute values), but later versions of an object are ordered before * earlier versions of the same object. This is useful when the last - * version of an object needs to be used. + * version of an object needs to be used. Object visibility is not taken + * into account, so objects with different visibilities keep their order. */ struct object_order_type_id_reverse_version { bool operator()(const osmium::OSMObject& lhs, const osmium::OSMObject& rhs) const noexcept { + const bool tsvalid = lhs.timestamp().valid() && rhs.timestamp().valid(); return const_tie(lhs.type(), lhs.id() > 0, lhs.positive_id(), rhs.version(), - ((lhs.timestamp().valid() && rhs.timestamp().valid()) ? rhs.timestamp() : osmium::Timestamp()), - rhs.visible()) < + (tsvalid ? rhs.timestamp() : osmium::Timestamp())) < const_tie(rhs.type(), rhs.id() > 0, rhs.positive_id(), lhs.version(), - ((lhs.timestamp().valid() && rhs.timestamp().valid()) ? lhs.timestamp() : osmium::Timestamp()), - lhs.visible()); + (tsvalid ? lhs.timestamp() : osmium::Timestamp())); } /// @pre lhs and rhs must not be nullptr diff --git a/test/t/osm/test_object_comparisons.cpp b/test/t/osm/test_object_comparisons.cpp index 2ff41276..a8d011d9 100644 --- a/test/t/osm/test_object_comparisons.cpp +++ b/test/t/osm/test_object_comparisons.cpp @@ -195,11 +195,18 @@ TEST_CASE("Node comparisons") { REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{})); } - SECTION("reverse version ordering should order objects with deleted flag last") { + SECTION("reverse version ordering should keep order for deleted objects") { nodes.emplace_back(buffer.get(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(false)))); nodes.emplace_back(buffer.get(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(true)))); REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{})); + + nodes.clear(); + + nodes.emplace_back(buffer.get(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(true)))); + nodes.emplace_back(buffer.get(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"), _deleted(false)))); + + REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{})); } }