Bug 1119199 - Rewrite UniquePtr with variadic template. r=waldo
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 13 Jan 2015 10:48:10 +1100
changeset 223422 accc4cc9009e
parent 223421 aa2eb48a20d9
child 223423 428abebd41a3
push id53905
push userxquan@mozilla.com
push dateMon, 12 Jan 2015 23:48:49 +0000
treeherdermozilla-inbound@428abebd41a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1119199
milestone38.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 1119199 - Rewrite UniquePtr with variadic template. r=waldo
mfbt/UniquePtr.h
--- a/mfbt/UniquePtr.h
+++ b/mfbt/UniquePtr.h
@@ -664,142 +664,30 @@ struct UniqueSelector<T[N]>
 // We don't have variadic template support everywhere, so just hard-code arities
 // 0-8 for now.  If you need more arguments, feel free to add the extra
 // overloads (and deletions for the T = E[N] case).
 //
 // Beware!  Due to lack of true nullptr support in gcc 4.4 and 4.5, passing
 // literal nullptr to MakeUnique will not work on some platforms.  See Move.h
 // for more details.
 
-template<typename T>
-typename detail::UniqueSelector<T>::SingleObject
-MakeUnique()
-{
-  return UniquePtr<T>(new T());
-}
-
-template<typename T, typename A1>
-typename detail::UniqueSelector<T>::SingleObject
-MakeUnique(A1&& aA1)
-{
-  return UniquePtr<T>(new T(Forward<A1>(aA1)));
-}
-
-template<typename T, typename A1, typename A2>
+template<typename T, typename... Args>
 typename detail::UniqueSelector<T>::SingleObject
-MakeUnique(A1&& aA1, A2&& aA2)
-{
-  return UniquePtr<T>(new T(Forward<A1>(aA1), Forward<A2>(aA2)));
-}
-
-template<typename T, typename A1, typename A2, typename A3>
-typename detail::UniqueSelector<T>::SingleObject
-MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3)
-{
-  return UniquePtr<T>(new T(Forward<A1>(aA1), Forward<A2>(aA2),
-                            Forward<A3>(aA3)));
-}
-
-template<typename T, typename A1, typename A2, typename A3, typename A4>
-typename detail::UniqueSelector<T>::SingleObject
-MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3, A4&& aA4)
+MakeUnique(Args&&... aArgs)
 {
-  return UniquePtr<T>(new T(Forward<A1>(aA1), Forward<A2>(aA2),
-                            Forward<A3>(aA3), Forward<A4>(aA4)));
-}
-
-template<typename T, typename A1, typename A2, typename A3, typename A4,
-         typename A5>
-typename detail::UniqueSelector<T>::SingleObject
-MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3, A4&& aA4, A5&& aA5)
-{
-  return UniquePtr<T>(new T(Forward<A1>(aA1), Forward<A2>(aA2),
-                            Forward<A3>(aA3), Forward<A4>(aA4),
-                            Forward<A5>(aA5)));
-}
-
-template<typename T, typename A1, typename A2, typename A3, typename A4,
-         typename A5, typename A6>
-typename detail::UniqueSelector<T>::SingleObject
-MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6)
-{
-  return UniquePtr<T>(new T(Forward<A1>(a1), Forward<A2>(a2),
-                            Forward<A3>(a3), Forward<A4>(a4),
-                            Forward<A5>(a5), Forward<A6>(a6)));
-}
-
-template<typename T, typename A1, typename A2, typename A3, typename A4,
-         typename A5, typename A6, typename A7>
-typename detail::UniqueSelector<T>::SingleObject
-MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, A7&& a7)
-{
-  return UniquePtr<T>(new T(Forward<A1>(a1), Forward<A2>(a2),
-                            Forward<A3>(a3), Forward<A4>(a4),
-                            Forward<A5>(a5), Forward<A6>(a6),
-                            Forward<A7>(a7)));
-}
-
-template<typename T, typename A1, typename A2, typename A3, typename A4,
-         typename A5, typename A6, typename A7, typename A8>
-typename detail::UniqueSelector<T>::SingleObject
-MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6, A7&& a7,
-           A8&& a8)
-{
-  return UniquePtr<T>(new T(Forward<A1>(a1), Forward<A2>(a2),
-                            Forward<A3>(a3), Forward<A4>(a4),
-                            Forward<A5>(a5), Forward<A6>(a6),
-                            Forward<A7>(a7), Forward<A8>(a8)));
+  return UniquePtr<T>(new T(Forward<Args>(aArgs)...));
 }
 
 template<typename T>
 typename detail::UniqueSelector<T>::UnknownBound
 MakeUnique(decltype(sizeof(int)) aN)
 {
   typedef typename RemoveExtent<T>::Type ArrayType;
   return UniquePtr<T>(new ArrayType[aN]());
 }
 
-template<typename T>
-typename detail::UniqueSelector<T>::KnownBound
-MakeUnique() = delete;
-
-template<typename T, typename A1>
-typename detail::UniqueSelector<T>::KnownBound
-MakeUnique(A1&& aA1) = delete;
-
-template<typename T, typename A1, typename A2>
-typename detail::UniqueSelector<T>::KnownBound
-MakeUnique(A1&& aA1, A2&& aA2) = delete;
-
-template<typename T, typename A1, typename A2, typename A3>
-typename detail::UniqueSelector<T>::KnownBound
-MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3) = delete;
-
-template<typename T, typename A1, typename A2, typename A3, typename A4>
+template<typename T, typename... Args>
 typename detail::UniqueSelector<T>::KnownBound
-MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3, A4&& aA4) = delete;
-
-template<typename T, typename A1, typename A2, typename A3, typename A4,
-         typename A5>
-typename detail::UniqueSelector<T>::KnownBound
-MakeUnique(A1&& aA1, A2&& aA2, A3&& aA3, A4&& aA4, A5&& aA5) = delete;
-
-template<typename T, typename A1, typename A2, typename A3, typename A4,
-         typename A5, typename A6>
-typename detail::UniqueSelector<T>::KnownBound
-MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5,
-           A6&& a6) = delete;
-
-template<typename T, typename A1, typename A2, typename A3, typename A4,
-         typename A5, typename A6, typename A7>
-typename detail::UniqueSelector<T>::KnownBound
-MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6,
-           A7&& a7) = delete;
-
-template<typename T, typename A1, typename A2, typename A3, typename A4,
-         typename A5, typename A6, typename A7, typename A8>
-typename detail::UniqueSelector<T>::KnownBound
-MakeUnique(A1&& a1, A2&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6,
-           A7&& a7, A8&& a8) = delete;
+MakeUnique(Args&&... aArgs) = delete;
 
 } // namespace mozilla
 
 #endif /* mozilla_UniquePtr_h */