cleanup label_ptr.h
Use C++11 default initializers, and remove un-needed template
predicates. The only one which was used was LabelPtrLabelLess
which is entirely redundant, since the default std::less<>
implementation will pick the global operator<() definition.
R=dpranke@chromium.org,brettw@chromium.org
BUG=NONE
Change-Id: Ie3383a60eb67aafdf25666470dab5368f29f8cec
Reviewed-on: https://gn-review.googlesource.com/c/3661
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/tools/gn/desc_builder.cc b/tools/gn/desc_builder.cc
index d4b4941..e377f3e 100644
--- a/tools/gn/desc_builder.cc
+++ b/tools/gn/desc_builder.cc
@@ -538,8 +538,7 @@
std::vector<LabelTargetPair> sorted_deps;
for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
sorted_deps.push_back(pair);
- std::sort(sorted_deps.begin(), sorted_deps.end(),
- LabelPtrLabelLess<Target>());
+ std::sort(sorted_deps.begin(), sorted_deps.end());
std::string indent(indent_level * 2, ' ');
diff --git a/tools/gn/label_ptr.h b/tools/gn/label_ptr.h
index 5aaa02d..ac994f5 100644
--- a/tools/gn/label_ptr.h
+++ b/tools/gn/label_ptr.h
@@ -24,25 +24,23 @@
struct LabelPtrPair {
typedef T DestType;
- LabelPtrPair() : label(), ptr(nullptr), origin(nullptr) {}
+ LabelPtrPair() = default;
- explicit LabelPtrPair(const Label& l)
- : label(l), ptr(nullptr), origin(nullptr) {}
+ explicit LabelPtrPair(const Label& l) : label(l) {}
// This contructor is typically used in unit tests, it extracts the label
// automatically from a given pointer.
- explicit LabelPtrPair(const T* p)
- : label(p->label()), ptr(p), origin(nullptr) {}
+ explicit LabelPtrPair(const T* p) : label(p->label()), ptr(p) {}
- ~LabelPtrPair() {}
+ ~LabelPtrPair() = default;
Label label;
- const T* ptr; // May be NULL.
+ const T* ptr = nullptr;
// The origin of this dependency. This will be null for internally generated
// dependencies. This happens when a group is automatically expanded and that
// group's members are added to the target that depends on that group.
- const ParseNode* origin;
+ const ParseNode* origin = nullptr;
};
typedef LabelPtrPair<Config> LabelConfigPair;
@@ -51,41 +49,6 @@
typedef std::vector<LabelConfigPair> LabelConfigVector;
typedef std::vector<LabelTargetPair> LabelTargetVector;
-// Comparison and search functions ---------------------------------------------
-
-// To do a brute-force search by label:
-// std::find_if(vect.begin(), vect.end(), LabelPtrLabelEquals<Config>(label));
-template <typename T>
-struct LabelPtrLabelEquals {
- explicit LabelPtrLabelEquals(const Label& l) : label(l) {}
-
- bool operator()(const LabelPtrPair<T>& arg) const {
- return arg.label == label;
- }
-
- const Label& label;
-};
-
-// To do a brute-force search by object pointer:
-// std::find_if(vect.begin(), vect.end(), LabelPtrPtrEquals<Config>(config));
-template <typename T>
-struct LabelPtrPtrEquals {
- explicit LabelPtrPtrEquals(const T* p) : ptr(p) {}
-
- bool operator()(const LabelPtrPair<T>& arg) const { return arg.ptr == ptr; }
-
- const T* ptr;
-};
-
-// To sort by label:
-// std::sort(vect.begin(), vect.end(), LabelPtrLabelLess<Config>());
-template <typename T>
-struct LabelPtrLabelLess {
- bool operator()(const LabelPtrPair<T>& a, const LabelPtrPair<T>& b) const {
- return a.label < b.label;
- }
-};
-
// Default comparison operators -----------------------------------------------
//
// The default hash and comparison operators operate on the label, which should