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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef TOOLS_GN_DEREFERENCE_COMPARATOR_H_
6 #define TOOLS_GN_DEREFERENCE_COMPARATOR_H_
7
8 #include <functional>
9 #include <set>
10
11 // Comparator that dereferences the pointers before comparing them.
12 template <typename T, typename Comparator = std::less<T>>
13 class DereferenceComparator {
14 public:
15 // Constructs a DereferenceComparator that uses the provided comparator.
16 DereferenceComparator(const Comparator& comparator = Comparator())
17 : comparator(comparator) {}
18
19 // Compares the values pointed to by a and b with the comparator.
20 bool operator()(const T* a, const T* b) const {
21 DCHECK(a != nullptr);
22 DCHECK(b != nullptr);
23 return comparator(*a, *b);
24 }
25
26 private:
27 Comparator comparator;
28 };
29
30 // Typedefs for convenience.
31
32 // A set of pointers that are ordered by what they point at.
33 template <typename T, typename Comparator = std::less<T>>
34 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:
35
36 #endif // TOOLS_GN_DEREFERENCE_COMPARATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698