Make callable traits work with msvc.
The msvc preprocessor interprets empty parentheses as zero parameters
instead of as a single empty parameter. Work around this by making all
marcos which may take a single empty parameter also take a second
ignored parameter.
Change-Id: Iea8bd386b7ffe3c14eb048d81e18c42c8d2894d9
Reviewed-on: https://skia-review.googlesource.com/c/174306
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/src/utils/SkCallableTraits.h b/src/utils/SkCallableTraits.h
index 9103bf2..7df0124 100644
--- a/src/utils/SkCallableTraits.h
+++ b/src/utils/SkCallableTraits.h
@@ -19,32 +19,31 @@
};
};
-#define SK_CALLABLE_TRAITS__EMPTY
#define SK_CALLABLE_TRAITS__COMMA ,
-#define SK_CALLABLE_TRAITS__VARARGS(quals) \
-SK_CALLABLE_TRAITS__INSTANCE(quals, SK_CALLABLE_TRAITS__EMPTY) \
+#define SK_CALLABLE_TRAITS__VARARGS(quals, _) \
+SK_CALLABLE_TRAITS__INSTANCE(quals,) \
SK_CALLABLE_TRAITS__INSTANCE(quals, SK_CALLABLE_TRAITS__COMMA ...)
#ifdef __cpp_noexcept_function_type
-#define SK_CALLABLE_TRAITS__NE_VARARGS(quals) \
-SK_CALLABLE_TRAITS__VARARGS(quals) \
-SK_CALLABLE_TRAITS__VARARGS(quals noexcept)
+#define SK_CALLABLE_TRAITS__NE_VARARGS(quals, _) \
+SK_CALLABLE_TRAITS__VARARGS(quals,) \
+SK_CALLABLE_TRAITS__VARARGS(quals noexcept,)
#else
-#define SK_CALLABLE_TRAITS__NE_VARARGS(quals) \
-SK_CALLABLE_TRAITS__VARARGS(quals)
+#define SK_CALLABLE_TRAITS__NE_VARARGS(quals, _) \
+SK_CALLABLE_TRAITS__VARARGS(quals,)
#endif
-#define SK_CALLABLE_TRAITS__REF_NE_VARARGS(quals) \
-SK_CALLABLE_TRAITS__NE_VARARGS(quals) \
-SK_CALLABLE_TRAITS__NE_VARARGS(quals &) \
-SK_CALLABLE_TRAITS__NE_VARARGS(quals &&)
+#define SK_CALLABLE_TRAITS__REF_NE_VARARGS(quals, _) \
+SK_CALLABLE_TRAITS__NE_VARARGS(quals,) \
+SK_CALLABLE_TRAITS__NE_VARARGS(quals &,) \
+SK_CALLABLE_TRAITS__NE_VARARGS(quals &&,)
#define SK_CALLABLE_TRAITS__CV_REF_NE_VARARGS() \
-SK_CALLABLE_TRAITS__REF_NE_VARARGS(SK_CALLABLE_TRAITS__EMPTY) \
-SK_CALLABLE_TRAITS__REF_NE_VARARGS(const) \
-SK_CALLABLE_TRAITS__REF_NE_VARARGS(volatile) \
-SK_CALLABLE_TRAITS__REF_NE_VARARGS(const volatile)
+SK_CALLABLE_TRAITS__REF_NE_VARARGS(,) \
+SK_CALLABLE_TRAITS__REF_NE_VARARGS(const,) \
+SK_CALLABLE_TRAITS__REF_NE_VARARGS(volatile,) \
+SK_CALLABLE_TRAITS__REF_NE_VARARGS(const volatile,)
/** Infer the return_type and argument<N> of a callable type T. */
template <typename T> struct SkCallableTraits : SkCallableTraits<decltype(&T::operator())> {};
@@ -62,7 +61,7 @@
template <typename R, typename... Args> \
struct SkCallableTraits<R(*)(Args... varargs) quals> : sk_base_callable_traits<R, Args...> {};
-SK_CALLABLE_TRAITS__NE_VARARGS()
+SK_CALLABLE_TRAITS__NE_VARARGS(,)
#undef SK_CALLABLE_TRAITS__INSTANCE
// pointer to method (..., (const, volatile), (&, &&), noexcept)
@@ -82,6 +81,5 @@
#undef SK_CALLABLE_TRAITS__NE_VARARGS
#undef SK_CALLABLE_TRAITS__VARARGS
#undef SK_CALLABLE_TRAITS__COMMA
-#undef SK_CALLABLE_TRAITS__EMPTY
#endif