OLD | NEW |
---|---|
(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_ | |
OLD | NEW |