Take modifiers as tuple

This commit is contained in:
Alexander Grund 2025-04-20 14:36:30 +02:00
parent 09bb6b5371
commit a8f0253753
2 changed files with 18 additions and 12 deletions

View file

@ -77,20 +77,21 @@ namespace mock { namespace detail {
BOOST_PP_TUPLE_ELEM(3, M_n_S_t), \ BOOST_PP_TUPLE_ELEM(3, M_n_S_t), \
qualifier) qualifier)
/// MOCK_METHOD_EXT_IMPL( name, arity, signature, identifier, qualifiers... ) #define MOCK_METHOD_EXT_IMPL(name, arity, signature, identifier, qualifiers) \
#define MOCK_METHOD_EXT_IMPL(name, arity, signature, identifier, ...) \
static_assert(arity == mock::detail::function_arity_t<signature>::value, "Arity mismatch"); \ static_assert(arity == mock::detail::function_arity_t<signature>::value, "Arity mismatch"); \
MOCK_PP_FOR_EACH(MOCK_METHOD_ITER, (name, arity, signature, identifier), __VA_ARGS__) \ MOCK_PP_TUPLE_FOR_EACH(MOCK_METHOD_ITER, (name, arity, signature, identifier), qualifiers) \
MOCK_METHOD_HELPER(signature, identifier) MOCK_METHOD_HELPER(signature, identifier)
/// MOCK_METHOD_EXT( name, arity, signature, identifier [ , qualifiers...] ) /// MOCK_METHOD_EXT( name, arity, signature, identifier [ , qualifiers] )
/// If qualifiers is not given, defaults to (const, ), i.e. const and non-const /// If qualifiers is not given, defaults to (const, ), i.e. const and non-const
#define MOCK_METHOD_EXT(...) \ #define MOCK_METHOD_EXT(name, arity, signature, ...) \
MOCK_METHOD_EXT_IMPL \ MOCK_METHOD_EXT_IMPL \
BOOST_PP_IF(BOOST_PP_LESS_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 4), (__VA_ARGS__, const, ), (__VA_ARGS__)) BOOST_PP_IF(BOOST_PP_LESS_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 1), \
(name, arity, signature, __VA_ARGS__, (const, )), \
(name, arity, signature, __VA_ARGS__))
#define MOCK_CONST_METHOD_EXT(M, n, S, t) MOCK_METHOD_EXT(M, n, S, t, const) #define MOCK_CONST_METHOD_EXT(M, n, S, t) MOCK_METHOD_EXT(M, n, S, t, (const))
#define MOCK_NON_CONST_METHOD_EXT(M, n, S, t) MOCK_METHOD_EXT(M, n, S, t, ) #define MOCK_NON_CONST_METHOD_EXT(M, n, S, t) MOCK_METHOD_EXT(M, n, S, t, ())
#define MOCK_FUNCTION_HELPER(signature, identifier, prefix) \ #define MOCK_FUNCTION_HELPER(signature, identifier, prefix) \
prefix mock::detail::function<signature>& identifier##_mock(mock::detail::context& context, \ prefix mock::detail::function<signature>& identifier##_mock(mock::detail::context& context, \

View file

@ -9,12 +9,17 @@
#ifndef MOCK_PP_FOREACH_HPP_INCLUDED #ifndef MOCK_PP_FOREACH_HPP_INCLUDED
#define MOCK_PP_FOREACH_HPP_INCLUDED #define MOCK_PP_FOREACH_HPP_INCLUDED
#include <boost/preprocessor/expand.hpp> #include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/empty.hpp>
#include <boost/preprocessor/facilities/overload.hpp> #include <boost/preprocessor/facilities/overload.hpp>
#include <boost/preprocessor/tuple/rem.hpp>
/// Expand to `macro(data, elem)` for each element passed, similar to BOOST_PP_*_FOR_EACH /// Expand to `macro(data, elem)` for each element in the tuple.
/// It supports empty arguments, /// Same as BOOST_PP_TUPLE_FOR_EACH but supports empty elements,
/// without causing a C4003 "not enough arguments for function-like macro invocation" warning on MSVC /// without causing a C4003 "not enough arguments for function-like macro invocation" warning on MSVC
#define MOCK_PP_TUPLE_FOR_EACH(macro, data, tuple) MOCK_PP_FOR_EACH(macro, data, BOOST_PP_REM tuple)
/// Expand to `macro(data, elem)` for each variadic element passed
#if BOOST_PP_VARIADICS_MSVC #if BOOST_PP_VARIADICS_MSVC
# define MOCK_PP_FOR_EACH(macro, data, ...) \ # define MOCK_PP_FOR_EACH(macro, data, ...) \
BOOST_PP_CAT(BOOST_PP_OVERLOAD(MOCK_PP_INVOKE_, __VA_ARGS__)(macro, data, __VA_ARGS__), BOOST_PP_EMPTY()) BOOST_PP_CAT(BOOST_PP_OVERLOAD(MOCK_PP_INVOKE_, __VA_ARGS__)(macro, data, __VA_ARGS__), BOOST_PP_EMPTY())