Bug 1232418 - Allow mozilla::Tuple to support equality comparison; r=Waldo
authorTerrence Cole <terrence@mozilla.com>
Mon, 14 Dec 2015 12:01:17 -0800
changeset 291759 b668ab1846b0170427ff3a3e74e41c706a4464c1
parent 291758 e6b28d1a8a043194ae6c42e2c1d645ba7f475d11
child 291760 2c8c35258999b32422bea205da5c5cecee7961a6
push id74660
push usertcole@mozilla.com
push dateTue, 05 Apr 2016 18:51:55 +0000
treeherdermozilla-inbound@b668ab1846b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1232418
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1232418 - Allow mozilla::Tuple to support equality comparison; r=Waldo
mfbt/Tuple.h
--- a/mfbt/Tuple.h
+++ b/mfbt/Tuple.h
@@ -90,17 +90,22 @@ struct CheckConvertibility<Group<SourceT
 template<std::size_t Index, typename... Elements>
 struct TupleImpl;
 
 /*
  * The base case of the inheritance recursion (and also the implementation
  * of an empty tuple).
  */
 template<std::size_t Index>
-struct TupleImpl<Index> {};
+struct TupleImpl<Index> {
+  bool operator==(const TupleImpl<Index>& aOther) const
+  {
+    return true;
+  }
+};
 
 /*
  * One node of the recursive inheritance hierarchy. It stores the element at
  * index 'Index' of a tuple, of type 'HeadT', and inherits from the nodes
  * that store the remaining elements, of types 'TailT...'.
  */
 template<std::size_t Index, typename HeadT, typename... TailT>
 struct TupleImpl<Index, HeadT, TailT...>
@@ -177,16 +182,20 @@ struct TupleImpl<Index, HeadT, TailT...>
     return *this;
   }
   TupleImpl& operator=(TupleImpl&& aOther)
   {
     Head(*this) = Move(Head(aOther));
     Tail(*this) = Move(Tail(aOther));
     return *this;
   }
+  bool operator==(const TupleImpl& aOther) const
+  {
+    return Head(*this) == Head(aOther) && Tail(*this) == Tail(aOther);
+  }
 private:
   HeadT mHead;  // The element stored at this index in the tuple.
 };
 
 } // namespace detail
 
 /**
  * Tuple is a class that stores zero or more objects, whose types are specified
@@ -241,16 +250,20 @@ public:
     static_cast<Impl&>(*this) = aOther;
     return *this;
   }
   Tuple& operator=(Tuple&& aOther)
   {
     static_cast<Impl&>(*this) = Move(aOther);
     return *this;
   }
+  bool operator==(const Tuple& aOther) const
+  {
+    return static_cast<const Impl&>(*this) == static_cast<const Impl&>(aOther);
+  }
 };
 
 /**
  * Specialization of Tuple for two elements.
  * This is created to support construction and assignment from a Pair or std::pair.
  */
 template <typename A, typename B>
 class Tuple<A, B> : public detail::TupleImpl<0, A, B>