From dc08c516bf0af3a080305bb311f8ebb4c7030108 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Feb 2015 19:15:16 +0100 Subject: [PATCH] use std::tie() to simplify lexicographic comparisons --- data_structures/dynamic_graph.hpp | 8 ++------ data_structures/query_edge.hpp | 18 ++++++++---------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/data_structures/dynamic_graph.hpp b/data_structures/dynamic_graph.hpp index 498f94a7c..3a8f520c6 100644 --- a/data_structures/dynamic_graph.hpp +++ b/data_structures/dynamic_graph.hpp @@ -67,13 +67,9 @@ template class DynamicGraph { } - bool operator<(const InputEdge &right) const + bool operator<(const InputEdge &rhs) const { - if (source != right.source) - { - return source < right.source; - } - return target < right.target; + return std::tie(source, target) < std::tie(rhs.source, rhs.target); } }; diff --git a/data_structures/query_edge.hpp b/data_structures/query_edge.hpp index 0d51aac3f..417bb4a13 100644 --- a/data_structures/query_edge.hpp +++ b/data_structures/query_edge.hpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2014, Project OSRM contributors +Copyright (c) 2015, Project OSRM contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -25,11 +25,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef QUERYEDGE_HPP_ -#define QUERYEDGE_HPP_ +#ifndef QUERYEDGE_HPP +#define QUERYEDGE_HPP #include "../typedefs.h" +#include + struct QueryEdge { NodeID source; @@ -60,13 +62,9 @@ struct QueryEdge { } - bool operator<(const QueryEdge &right) const + bool operator<(const QueryEdge &rhs) const { - if (source != right.source) - { - return source < right.source; - } - return target < right.target; + return std::tie(source, target) < std::tie(rhs.source, rhs.target); } bool operator==(const QueryEdge &right) const @@ -78,4 +76,4 @@ struct QueryEdge } }; -#endif /* QUERYEDGE_HPP_ */ +#endif // QUERYEDGE_HPP