commit 2107bd099e665885c381b8820f2bf158e3b220b3
parent 873685d76c7ccb6ac59d68a1d973cefa12efe531
Author: Cristina Horotan <chorotan@mozilla.com>
Date: Mon, 6 Oct 2025 16:50:26 +0300
Revert "Bug 1992681 - Cleanup mfbt/FunctionTypeTraits.h r=emilio" for causing build bustages on FunctionTypeTraits.h
This reverts commit df6809ea3938e70cfea8ebf1485f46145d509a39.
Diffstat:
2 files changed, 34 insertions(+), 30 deletions(-)
diff --git a/dom/canvas/WebGLCommandQueue.h b/dom/canvas/WebGLCommandQueue.h
@@ -10,6 +10,7 @@
#include "QueueParamTraits.h"
#include "WebGLTypes.h"
+#include "mozilla/FunctionTypeTraits.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/ipc/IPDLParamTraits.h"
diff --git a/mfbt/FunctionTypeTraits.h b/mfbt/FunctionTypeTraits.h
@@ -8,6 +8,7 @@
#define mozilla_FunctionTypeTraits_h
#include <cstddef> /* for size_t */
+#include <tuple>
namespace mozilla {
@@ -39,71 +40,73 @@ struct FunctionTypeTraits;
// Remove reference and pointer wrappers, if any.
template <typename T>
-struct FunctionTypeTraits<T&> : FunctionTypeTraits<T> {};
+struct FunctionTypeTraits<T&> : public FunctionTypeTraits<T> {};
template <typename T>
-struct FunctionTypeTraits<T&&> : FunctionTypeTraits<T> {};
+struct FunctionTypeTraits<T&&> : public FunctionTypeTraits<T> {};
template <typename T>
-struct FunctionTypeTraits<T*> : FunctionTypeTraits<T> {};
+struct FunctionTypeTraits<T*> : public FunctionTypeTraits<T> {};
// Extract `operator()` function from callables (e.g. lambdas, std::function).
template <typename T>
-struct FunctionTypeTraits : FunctionTypeTraits<decltype(&T::operator())> {};
+struct FunctionTypeTraits
+ : public FunctionTypeTraits<decltype(&T::operator())> {};
namespace detail {
-template <size_t N, typename... As>
-struct SafePackElement;
-
-template <size_t N>
-struct SafePackElement<N> {
- using type = void;
-};
-template <typename A, typename... As>
-struct SafePackElement<0, A, As...> {
- using type = A;
+// If `safe`, retrieve the `N`th type from `As`, otherwise `void`.
+// See top description for reason.
+template <bool safe, size_t N, typename... As>
+struct TupleElementSafe;
+template <size_t N, typename... As>
+struct TupleElementSafe<true, N, As...> {
+ using Type = typename std::tuple_element<N, std::tuple<As...>>::type;
};
-
-template <size_t N, typename A, typename... As>
-struct SafePackElement<N, A, As...> : SafePackElement<N - 1, As...> {};
-
template <size_t N, typename... As>
-using SafePackElementType = typename SafePackElement<N, As...>::type;
-
-} // namespace detail
+struct TupleElementSafe<false, N, As...> {
+ using Type = void;
+};
-// Specialization for free functions.
template <typename R, typename... As>
-struct FunctionTypeTraits<R(As...)> {
+struct FunctionTypeTraitsHelper {
using ReturnType = R;
static constexpr size_t arity = sizeof...(As);
template <size_t N>
- using ParameterType = detail::SafePackElementType<N, As...>;
+ using ParameterType =
+ typename TupleElementSafe<(N < sizeof...(As)), N, As...>::Type;
};
+} // namespace detail
+
+// Specialization for free functions.
+template <typename R, typename... As>
+struct FunctionTypeTraits<R(As...)>
+ : detail::FunctionTypeTraitsHelper<R, As...> {};
+
// Specialization for non-const member functions.
template <typename C, typename R, typename... As>
-struct FunctionTypeTraits<R (C::*)(As...)> : FunctionTypeTraits<R(As...)> {};
+struct FunctionTypeTraits<R (C::*)(As...)>
+ : detail::FunctionTypeTraitsHelper<R, As...> {};
// Specialization for const member functions.
template <typename C, typename R, typename... As>
struct FunctionTypeTraits<R (C::*)(As...) const>
- : FunctionTypeTraits<R(As...)> {};
+ : detail::FunctionTypeTraitsHelper<R, As...> {};
#ifdef NS_HAVE_STDCALL
// Specialization for __stdcall free functions.
template <typename R, typename... As>
-struct FunctionTypeTraits<R NS_STDCALL(As...)> : FunctionTypeTraits<R(As...)> {
-};
+struct FunctionTypeTraits<R NS_STDCALL(As...)>
+ : detail::FunctionTypeTraitsHelper<R, As...> {};
// Specialization for __stdcall non-const member functions.
template <typename C, typename R, typename... As>
struct FunctionTypeTraits<R (NS_STDCALL C::*)(As...)>
- : FunctionTypeTraits<R(As...)> {};
+ : detail::FunctionTypeTraitsHelper<R, As...> {};
// Specialization for __stdcall const member functions.
template <typename C, typename R, typename... As>
struct FunctionTypeTraits<R (NS_STDCALL C::*)(As...) const>
- : FunctionTypeTraitsHelper<R(As...)> {};
+ : detail::FunctionTypeTraitsHelper<R, As...> {};
#endif // NS_HAVE_STDCALL
} // namespace mozilla