AAPT2: Improve diff command
Change-Id: Ia1e2f8482c7192ef50126b61bed7975297332767
diff --git a/tools/aapt2/util/Maybe.h b/tools/aapt2/util/Maybe.h
index 595db96..a31bc89 100644
--- a/tools/aapt2/util/Maybe.h
+++ b/tools/aapt2/util/Maybe.h
@@ -88,6 +88,8 @@
*/
const T& value() const;
+ T valueOrDefault(const T& def) const;
+
private:
template <typename U>
friend class Maybe;
@@ -263,6 +265,14 @@
}
template <typename T>
+T Maybe<T>::valueOrDefault(const T& def) const {
+ if (mNothing) {
+ return def;
+ }
+ return reinterpret_cast<const T&>(mStorage);
+}
+
+template <typename T>
void Maybe<T>::destroy() {
reinterpret_cast<T&>(mStorage).~T();
}
@@ -306,6 +316,19 @@
return !(a == b);
}
+template <typename T, typename U>
+typename std::enable_if<
+ has_lt_op<T, U>::value,
+ bool
+>::type operator<(const Maybe<T>& a, const Maybe<U>& b) {
+ if (a && b) {
+ return a.value() < b.value();
+ } else if (!a && !b) {
+ return false;
+ }
+ return !a;
+}
+
} // namespace aapt
#endif // AAPT_MAYBE_H