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

Unified Diff: tools/gn/label_ptr.h

Issue 26537002: Add a UniqueVector class to GN (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: REview comments, remove npos Created 6 years, 4 months 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
« no previous file with comments | « tools/gn/label.h ('k') | tools/gn/ninja_binary_target_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/label_ptr.h
diff --git a/tools/gn/label_ptr.h b/tools/gn/label_ptr.h
index f2519d30953ab4c045c05667fb3f85cbc0df0a1f..771b14ba3fce1a767a6d8405433d32afb8c7a405 100644
--- a/tools/gn/label_ptr.h
+++ b/tools/gn/label_ptr.h
@@ -7,7 +7,11 @@
#include <functional>
+#include "tools/gn/label.h"
+
+class Config;
class ParseNode;
+class Target;
// Structure that holds a labeled "thing". This is used for various places
// where we need to store lists of targets or configs. We sometimes populate
@@ -80,4 +84,37 @@ struct LabelPtrLabelLess : public std::binary_function<LabelPtrPair<T>,
}
};
+// Default comparison operators -----------------------------------------------
+//
+// The default hash and comparison operators operate on the label, which should
+// always be valid, whereas the pointer is sometimes null.
+
+template<typename T> inline bool operator==(const LabelPtrPair<T>& a,
+ const LabelPtrPair<T>& b) {
+ return a.label == b.label;
+}
+
+template<typename T> inline bool operator<(const LabelPtrPair<T>& a,
+ const LabelPtrPair<T>& b) {
+ return a.label < b.label;
+}
+
+namespace BASE_HASH_NAMESPACE {
+
+#if defined(COMPILER_GCC)
+template<typename T> struct hash< LabelPtrPair<T> > {
+ std::size_t operator()(const LabelPtrPair<T>& v) const {
+ BASE_HASH_NAMESPACE::hash<Label> h;
+ return h(v.label);
+ }
+};
+#elif defined(COMPILER_MSVC)
+template<typename T>
+inline size_t hash_value(const LabelPtrPair<T>& v) {
+ return BASE_HASH_NAMESPACE::hash_value(v.label);
+}
+#endif // COMPILER...
+
+} // namespace BASE_HASH_NAMESPACE
+
#endif // TOOLS_GN_LABEL_PTR_H_
« no previous file with comments | « tools/gn/label.h ('k') | tools/gn/ninja_binary_target_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698