Skip to content

Commit

Permalink
Googletest export
Browse files Browse the repository at this point in the history
Use C++11 variadic templates for Invoke in gmock-generated-actions.h.

Replace InvokeArgumentAdl with Invoke that uses C++11 variadic templates.

PiperOrigin-RevId: 288449236
  • Loading branch information
Abseil Team authored and Andy Soffer committed Jan 9, 2020
1 parent 306f375 commit 4b9c169
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 134 deletions.
16 changes: 16 additions & 0 deletions googlemock/include/gmock/gmock-actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,22 @@ class ActionHelper {
}
};

namespace invoke_argument {

// Appears in InvokeArgumentAdl's argument list to help avoid
// accidental calls to user functions of the same name.
struct AdlTag {};

// InvokeArgumentAdl - a helper for InvokeArgument.
// The basic overloads are provided here for generic functors.
// Overloads for other custom-callables are provided in the
// internal/custom/gmock-generated-actions.h header.
template <typename F, typename... Args>
auto InvokeArgumentAdl(AdlTag, F f, Args... args) -> decltype(f(args...)) {
return f(args...);
}

} // namespace invoke_argument
} // namespace internal

} // namespace testing
Expand Down
129 changes: 24 additions & 105 deletions googlemock/include/gmock/gmock-generated-actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1501,175 +1501,94 @@ namespace testing {
// InvokeArgument action from temporary values and have it performed
// later.

namespace internal {
namespace invoke_argument {

// Appears in InvokeArgumentAdl's argument list to help avoid
// accidental calls to user functions of the same name.
struct AdlTag {};

// InvokeArgumentAdl - a helper for InvokeArgument.
// The basic overloads are provided here for generic functors.
// Overloads for other custom-callables are provided in the
// internal/custom/gmock-generated-actions.h header.

template <typename R, typename F>
R InvokeArgumentAdl(AdlTag, F f) {
return f();
}
template <typename R, typename F, typename A1>
R InvokeArgumentAdl(AdlTag, F f, A1 a1) {
return f(a1);
}
template <typename R, typename F, typename A1, typename A2>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2) {
return f(a1, a2);
}
template <typename R, typename F, typename A1, typename A2, typename A3>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3) {
return f(a1, a2, a3);
}
template <typename R, typename F, typename A1, typename A2, typename A3,
typename A4>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4) {
return f(a1, a2, a3, a4);
}
template <typename R, typename F, typename A1, typename A2, typename A3,
typename A4, typename A5>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
return f(a1, a2, a3, a4, a5);
}
template <typename R, typename F, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
return f(a1, a2, a3, a4, a5, a6);
}
template <typename R, typename F, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6, typename A7>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
A7 a7) {
return f(a1, a2, a3, a4, a5, a6, a7);
}
template <typename R, typename F, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6, typename A7, typename A8>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
A7 a7, A8 a8) {
return f(a1, a2, a3, a4, a5, a6, a7, a8);
}
template <typename R, typename F, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6, typename A7, typename A8,
typename A9>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
A7 a7, A8 a8, A9 a9) {
return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
}
template <typename R, typename F, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6, typename A7, typename A8,
typename A9, typename A10>
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
A7 a7, A8 a8, A9 a9, A10 a10) {
return f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
}
} // namespace invoke_argument
} // namespace internal

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_0_VALUE_PARAMS()) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args));
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args));
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_1_VALUE_PARAMS(p0)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_2_VALUE_PARAMS(p0, p1)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_3_VALUE_PARAMS(p0, p1, p2)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7,
p8);
}

ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7,
p8, p9);
}

// Various overloads for ReturnNew<T>().
Expand Down
31 changes: 2 additions & 29 deletions googlemock/include/gmock/gmock-generated-actions.h.pump
Original file line number Diff line number Diff line change
Expand Up @@ -506,32 +506,6 @@ namespace testing {
// InvokeArgument action from temporary values and have it performed
// later.

namespace internal {
namespace invoke_argument {

// Appears in InvokeArgumentAdl's argument list to help avoid
// accidental calls to user functions of the same name.
struct AdlTag {};

// InvokeArgumentAdl - a helper for InvokeArgument.
// The basic overloads are provided here for generic functors.
// Overloads for other custom-callables are provided in the
// internal/custom/gmock-generated-actions.h header.

$range i 0..n
$for i
[[
$range j 1..i

template <typename R, typename F[[$for j [[, typename A$j]]]]>
R InvokeArgumentAdl(AdlTag, F f[[$for j [[, A$j a$j]]]]) {
return f([[$for j, [[a$j]]]]);
}
]]

} // namespace invoke_argument
} // namespace internal

$range i 0..n
$for i [[
$range j 0..i-1
Expand All @@ -540,9 +514,8 @@ ACTION_TEMPLATE(InvokeArgument,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])) {
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
::std::get<k>(args)$for j [[, p$j]]);
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
::std::get<k>(args)$for j[[, p$j]]);
}

]]
Expand Down

0 comments on commit 4b9c169

Please sign in to comment.