Use std::tie instead of std::make_tuple for lexicographical ordering.
authorMilian Wolff <mail@milianw.de>
Mon, 4 Jan 2016 21:41:47 +0000 (22:41 +0100)
committerMilian Wolff <mail@milianw.de>
Mon, 4 Jan 2016 21:41:47 +0000 (22:41 +0100)
std::tie takes the arguments by reference, whereas make_tuple copies
them. We want the former.

See also: http://www.cppsamples.com/common-tasks/lexicographic-ordering.html

accumulatedtracedata.h
gui/parser.cpp
heaptrack_interpret.cpp

index b3c6c88..e00958c 100644 (file)
@@ -42,14 +42,14 @@ struct InstructionPointer
 
     bool compareWithoutAddress(const InstructionPointer &other) const
     {
-        return std::make_tuple(moduleIndex, functionIndex, fileIndex, line)
-             < std::make_tuple(other.moduleIndex, other.functionIndex, other.fileIndex, other.line);
+        return std::tie(moduleIndex, functionIndex, fileIndex, line)
+             < std::tie(other.moduleIndex, other.functionIndex, other.fileIndex, other.line);
     }
 
     bool equalWithoutAddress(const InstructionPointer &other) const
     {
-        return std::make_tuple(moduleIndex, functionIndex, fileIndex, line)
-            == std::make_tuple(other.moduleIndex, other.functionIndex, other.fileIndex, other.line);
+        return std::tie(moduleIndex, functionIndex, fileIndex, line)
+            == std::tie(other.moduleIndex, other.functionIndex, other.fileIndex, other.line);
     }
 };
 
index 6acb7c9..6bbf03e 100644 (file)
@@ -264,7 +264,8 @@ struct ParserData final : public AccumulatedTraceData
         uint64_t allocations;
         bool operator<(const CountedAllocationInfo& rhs) const
         {
-            return make_tuple(info.size, allocations) < make_tuple(rhs.info.size, rhs.allocations);
+            return tie(info.size, allocations)
+                 < tie(rhs.info.size, rhs.allocations);
         }
     };
     vector<CountedAllocationInfo> allocationInfoCounter;
index 3e289fd..8845be3 100644 (file)
@@ -111,14 +111,14 @@ struct Module
 
     bool operator<(const Module& module) const
     {
-        return make_tuple(addressStart, addressEnd, moduleIndex)
-             < make_tuple(module.addressStart, module.addressEnd, module.moduleIndex);
+        return tie(addressStart, addressEnd, moduleIndex)
+             < tie(module.addressStart, module.addressEnd, module.moduleIndex);
     }
 
     bool operator!=(const Module& module) const
     {
-        return make_tuple(addressStart, addressEnd, moduleIndex)
-            != make_tuple(module.addressStart, module.addressEnd, module.moduleIndex);
+        return tie(addressStart, addressEnd, moduleIndex)
+            != tie(module.addressStart, module.addressEnd, module.moduleIndex);
     }
 
     uintptr_t addressStart;