Remove usage of Boost.MPL and reduce Boost.FunctionTypes usage

They are known to be slow on compilation and C++11 offer better alternatives
This commit is contained in:
Alexander Grund 2020-07-05 22:29:14 +02:00
parent df5b77af95
commit cf330e8c86
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
6 changed files with 94 additions and 115 deletions

View file

@ -10,10 +10,6 @@
#define MOCK_IS_FUNCTOR_HPP_INCLUDED
#include "../config.hpp"
#include <boost/function_types/is_callable_builtin.hpp>
#include <boost/utility/declval.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/make_void.hpp>
#include <type_traits>
@ -21,10 +17,6 @@ namespace mock
{
namespace detail
{
BOOST_MPL_HAS_XXX_TRAIT_DEF( result_type )
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( sig )
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( result )
template< typename F, typename P, class = void >
struct is_callable : std::false_type
{};
@ -33,15 +25,7 @@ namespace detail
{};
template< typename T, typename P >
struct is_functor
: boost::mpl::or_<
boost::function_types::is_callable_builtin< T >,
is_callable< T, P >,
has_result_type< T >,
has_result< T >,
has_sig< T >
>
{};
using is_functor = is_callable< T, P >;
}
} // mock

View file

@ -10,24 +10,56 @@
#define MOCK_PARAMETER_HPP_INCLUDED
#include "../config.hpp"
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/mpl/at.hpp>
namespace mock
{
namespace detail
{
template< typename Signature, int n >
struct parameter
template< class... >
struct tuple;
template< std::size_t I, class T >
struct tuple_element;
template< std::size_t I, class H, class... T >
struct tuple_element<I, tuple<H, T...>> : tuple_element<I-1, tuple<T...>>
{};
template< class H, class... T >
struct tuple_element<0, tuple<H, T...>>
{
typedef typename
boost::mpl::at_c<
typename
boost::function_types::parameter_types< Signature >,
n
>::type type;
using type = H;
};
template< typename Signature >
struct result_type;
template< typename R, typename... Args >
struct result_type< R(Args...) >
{
using type = R;
};
template< typename Signature >
struct function_arity;
template< typename R, typename... Args >
struct function_arity< R(Args...) >
{
static constexpr size_t value = sizeof...(Args);
};
template< typename Signature >
struct parameter_types;
template< typename R, typename... Args >
struct parameter_types< R(Args...) >
{
using type = tuple<Args...>;
};
template< typename Signature, int n >
using parameter = tuple_element< n, typename parameter_types<Signature>::type >;
}
} // mock

View file

@ -10,33 +10,47 @@
#define MOCK_SIGNATURE_HPP_INCLUDED
#include "../config.hpp"
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_type.hpp>
#include <boost/function_types/result_type.hpp>
#include <boost/mpl/single_view.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/pop_front.hpp>
#define BOOST_TYPEOF_SILENT
#include <boost/typeof/typeof.hpp>
#include <type_traits>
namespace mock
{
namespace detail
{
#define MOCK_NOARG
#define MOCK_STRIP_FUNCTION_QUALIFIERS(cv, ref) \
template< typename R, typename... Args > \
struct strip_function_qualifiers<R(Args...) cv ref > \
{ using type = R(Args...); }; \
template< typename R, typename... Args > \
struct strip_function_qualifiers<R(Args..., ...) cv ref > \
{ using type = R(Args..., ...); };
#define MOCK_STRIP_FUNCTION_QUALIFIERS_REF(cv) \
MOCK_STRIP_FUNCTION_QUALIFIERS(cv,) \
MOCK_STRIP_FUNCTION_QUALIFIERS(cv, &) \
MOCK_STRIP_FUNCTION_QUALIFIERS(cv, &&)
template<typename>
struct strip_function_qualifiers;
MOCK_STRIP_FUNCTION_QUALIFIERS_REF(MOCK_NOARG)
MOCK_STRIP_FUNCTION_QUALIFIERS_REF(const)
MOCK_STRIP_FUNCTION_QUALIFIERS_REF(volatile)
MOCK_STRIP_FUNCTION_QUALIFIERS_REF(const volatile)
#undef MOCK_NOARG
#undef MOCK_STRIP_FUNCTION_QUALIFIERS
#undef MOCK_STRIP_FUNCTION_QUALIFIERS_REF
template< typename M >
struct signature :
boost::function_types::function_type<
boost::mpl::joint_view<
boost::mpl::single_view<
typename
boost::function_types::result_type< M >::type
>,
typename boost::mpl::pop_front<
typename
boost::function_types::parameter_types< M >
>::type
>
>
struct signature;
template< typename R, typename... Args>
struct signature< R(Args...) >
{
using type = R(Args...);
};
template< typename Sig, typename C>
struct signature< Sig(C::*) >: signature< typename strip_function_qualifiers<Sig>::type >
{};
template< typename T >
@ -55,9 +69,9 @@ namespace detail
#define MOCK_SIGNATURE(M) \
mock::detail::signature< \
BOOST_TYPEOF( \
mock::detail::ambiguous_method_requires_to_specify_signature( \
&base_type::M ) ) \
std::remove_cv_t< std::remove_reference_t < decltype( \
mock::detail::ambiguous_method_requires_to_specify_signature( &base_type::M ) \
) > > \
>::type
#endif // MOCK_SIGNATURE_HPP_INCLUDED

View file

@ -22,7 +22,6 @@
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/utility/identity_type.hpp>
#include <boost/mpl/assert.hpp>
#define MOCK_CLASS(T) \
struct T : mock::object
@ -79,7 +78,7 @@
#define MOCK_DECL_PARAMS(n, S, tpn) \
BOOST_PP_REPEAT(n, MOCK_DECL_PARAM, MOCK_PARAM(S, tpn))
#define MOCK_DECL(M, n, S, c, tpn) \
tpn boost::function_types::result_type< \
tpn mock::detail::result_type< \
MOCK_FUNCTION_TYPE((S), tpn) >::type M( \
MOCK_DECL_PARAMS(n, S, tpn) ) c
@ -91,9 +90,7 @@
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
MOCK_DECL(M, n, S, c, tpn) \
{ \
BOOST_MPL_ASSERT_RELATION( n, ==, \
boost::function_types::function_arity< \
MOCK_FUNCTION_TYPE((S), tpn) >::value ); \
static_assert( n == mock::detail::function_arity< MOCK_FUNCTION_TYPE((S), tpn) >::value, "Arity mismatch" ); \
return MOCK_ANONYMOUS_HELPER(t)( \
MOCK_FORWARD_PARAMS(n, S, tpn) ); \
}
@ -171,9 +168,7 @@
MOCK_FUNCTION_HELPER(S, t, s, tpn) \
s MOCK_DECL(F, n, S,,tpn) \
{ \
BOOST_MPL_ASSERT_RELATION( n, ==, \
boost::function_types::function_arity< \
MOCK_FUNCTION_TYPE((S), tpn) >::value ); \
static_assert( n == mock::detail::function_arity< MOCK_FUNCTION_TYPE((S), tpn) >::value, "Arity mismatch" ); \
return MOCK_HELPER(t)( MOCK_FORWARD_PARAMS(n, S, tpn) ); \
}