Support for GCC/Clang of MOCK_PP_FOR_EACH

Some compilers support detection of an empty variadic macro element in
which case `BOOST_PP_VARIADIC_SIZE` returns "0" so `BOOST_PP_OVERLOAD`
calls the `macro_0` overload.
An empty variadic element should be considered as a single empty value.
So add that overload with this in mind.
This commit is contained in:
Flamefire 2025-04-27 17:25:42 +02:00 committed by Alexander Grund
parent 2880b24116
commit 59d531282e

View file

@ -27,6 +27,9 @@
# define MOCK_PP_FOR_EACH(macro, data, ...) BOOST_PP_OVERLOAD(MOCK_PP_INVOKE_, __VA_ARGS__)(macro, data, __VA_ARGS__)
#endif
// When the compiler supports detection of empty variadic element (e.g. Clang & GCC) Boost.PP returns a size of zero.
// However an empty variadic is a valid case: A single invocation with an empty element.
#define MOCK_PP_INVOKE_0(macro, data, x) macro(data, x)
#define MOCK_PP_INVOKE_1(macro, data, x) macro(data, x)
#define MOCK_PP_INVOKE_2(macro, data, x, ...) macro(data, x) MOCK_PP_INVOKE_1(macro, data, __VA_ARGS__)
#define MOCK_PP_INVOKE_3(macro, data, x, ...) macro(data, x) MOCK_PP_INVOKE_2(macro, data, __VA_ARGS__)