Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: tools/gn/dereference_comparator.h

Issue 1494883002: GN: Makes GN output deterministic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moves sort into ninja_toolchain_writer.cc for consistency Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/gn/dereference_comparator.h
diff --git a/tools/gn/dereference_comparator.h b/tools/gn/dereference_comparator.h
new file mode 100644
index 0000000000000000000000000000000000000000..47108c90939d71764613c4b3b7c61ebe1466ef0f
--- /dev/null
+++ b/tools/gn/dereference_comparator.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TOOLS_GN_DEREFERENCE_COMPARATOR_H_
+#define TOOLS_GN_DEREFERENCE_COMPARATOR_H_
+
+#include <functional>
+#include <set>
+
+// Comparator that dereferences the pointers before comparing them.
+template <typename T, typename Comparator = std::less<T>>
+class DereferenceComparator {
+ public:
+ // Constructs a DereferenceComparator that uses the provided comparator.
+ DereferenceComparator(const Comparator& comparator = Comparator())
+ : comparator(comparator) {}
+
+ // Compares the values pointed to by a and b with the comparator.
+ bool operator()(const T* a, const T* b) const {
+ DCHECK(a != nullptr);
+ DCHECK(b != nullptr);
+ return comparator(*a, *b);
+ }
+
+ private:
+ Comparator comparator;
+};
+
+// Typedefs for convenience.
+
+// A set of pointers that are ordered by what they point at.
+template <typename T, typename Comparator = std::less<T>>
+using PointerSet = std::set<T*, DereferenceComparator<T, Comparator>>;
M-A Ruel 2015/12/07 00:20:16 AFAIK, that's what std::set<> already does (?) Ot
Zachary Forman 2015/12/07 03:18:17 So the Target*s are 'unique' in that there is a 1:
+
+#endif // TOOLS_GN_DEREFERENCE_COMPARATOR_H_

Powered by Google App Engine
This is Rietveld 408576698