Skip to content

Commit 4b9c169

Browse files
Abseil TeamAndy Soffer
Abseil Team
authored and
Andy Soffer
committed
Googletest export
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
1 parent 306f375 commit 4b9c169

File tree

3 files changed

+42
-134
lines changed

3 files changed

+42
-134
lines changed

googlemock/include/gmock/gmock-actions.h

+16
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,22 @@ class ActionHelper {
12221222
}
12231223
};
12241224

1225+
namespace invoke_argument {
1226+
1227+
// Appears in InvokeArgumentAdl's argument list to help avoid
1228+
// accidental calls to user functions of the same name.
1229+
struct AdlTag {};
1230+
1231+
// InvokeArgumentAdl - a helper for InvokeArgument.
1232+
// The basic overloads are provided here for generic functors.
1233+
// Overloads for other custom-callables are provided in the
1234+
// internal/custom/gmock-generated-actions.h header.
1235+
template <typename F, typename... Args>
1236+
auto InvokeArgumentAdl(AdlTag, F f, Args... args) -> decltype(f(args...)) {
1237+
return f(args...);
1238+
}
1239+
1240+
} // namespace invoke_argument
12251241
} // namespace internal
12261242

12271243
} // namespace testing

googlemock/include/gmock/gmock-generated-actions.h

+24-105
Original file line numberDiff line numberDiff line change
@@ -1501,175 +1501,94 @@ namespace testing {
15011501
// InvokeArgument action from temporary values and have it performed
15021502
// later.
15031503

1504-
namespace internal {
1505-
namespace invoke_argument {
1506-
1507-
// Appears in InvokeArgumentAdl's argument list to help avoid
1508-
// accidental calls to user functions of the same name.
1509-
struct AdlTag {};
1510-
1511-
// InvokeArgumentAdl - a helper for InvokeArgument.
1512-
// The basic overloads are provided here for generic functors.
1513-
// Overloads for other custom-callables are provided in the
1514-
// internal/custom/gmock-generated-actions.h header.
1515-
1516-
template <typename R, typename F>
1517-
R InvokeArgumentAdl(AdlTag, F f) {
1518-
return f();
1519-
}
1520-
template <typename R, typename F, typename A1>
1521-
R InvokeArgumentAdl(AdlTag, F f, A1 a1) {
1522-
return f(a1);
1523-
}
1524-
template <typename R, typename F, typename A1, typename A2>
1525-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2) {
1526-
return f(a1, a2);
1527-
}
1528-
template <typename R, typename F, typename A1, typename A2, typename A3>
1529-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3) {
1530-
return f(a1, a2, a3);
1531-
}
1532-
template <typename R, typename F, typename A1, typename A2, typename A3,
1533-
typename A4>
1534-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4) {
1535-
return f(a1, a2, a3, a4);
1536-
}
1537-
template <typename R, typename F, typename A1, typename A2, typename A3,
1538-
typename A4, typename A5>
1539-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
1540-
return f(a1, a2, a3, a4, a5);
1541-
}
1542-
template <typename R, typename F, typename A1, typename A2, typename A3,
1543-
typename A4, typename A5, typename A6>
1544-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
1545-
return f(a1, a2, a3, a4, a5, a6);
1546-
}
1547-
template <typename R, typename F, typename A1, typename A2, typename A3,
1548-
typename A4, typename A5, typename A6, typename A7>
1549-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
1550-
A7 a7) {
1551-
return f(a1, a2, a3, a4, a5, a6, a7);
1552-
}
1553-
template <typename R, typename F, typename A1, typename A2, typename A3,
1554-
typename A4, typename A5, typename A6, typename A7, typename A8>
1555-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
1556-
A7 a7, A8 a8) {
1557-
return f(a1, a2, a3, a4, a5, a6, a7, a8);
1558-
}
1559-
template <typename R, typename F, typename A1, typename A2, typename A3,
1560-
typename A4, typename A5, typename A6, typename A7, typename A8,
1561-
typename A9>
1562-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
1563-
A7 a7, A8 a8, A9 a9) {
1564-
return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
1565-
}
1566-
template <typename R, typename F, typename A1, typename A2, typename A3,
1567-
typename A4, typename A5, typename A6, typename A7, typename A8,
1568-
typename A9, typename A10>
1569-
R InvokeArgumentAdl(AdlTag, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
1570-
A7 a7, A8 a8, A9 a9, A10 a10) {
1571-
return f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
1572-
}
1573-
} // namespace invoke_argument
1574-
} // namespace internal
1575-
15761504
ACTION_TEMPLATE(InvokeArgument,
15771505
HAS_1_TEMPLATE_PARAMS(int, k),
15781506
AND_0_VALUE_PARAMS()) {
15791507
using internal::invoke_argument::InvokeArgumentAdl;
1580-
return InvokeArgumentAdl<return_type>(
1581-
internal::invoke_argument::AdlTag(),
1582-
::std::get<k>(args));
1508+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1509+
::std::get<k>(args));
15831510
}
15841511

15851512
ACTION_TEMPLATE(InvokeArgument,
15861513
HAS_1_TEMPLATE_PARAMS(int, k),
15871514
AND_1_VALUE_PARAMS(p0)) {
15881515
using internal::invoke_argument::InvokeArgumentAdl;
1589-
return InvokeArgumentAdl<return_type>(
1590-
internal::invoke_argument::AdlTag(),
1591-
::std::get<k>(args), p0);
1516+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1517+
::std::get<k>(args), p0);
15921518
}
15931519

15941520
ACTION_TEMPLATE(InvokeArgument,
15951521
HAS_1_TEMPLATE_PARAMS(int, k),
15961522
AND_2_VALUE_PARAMS(p0, p1)) {
15971523
using internal::invoke_argument::InvokeArgumentAdl;
1598-
return InvokeArgumentAdl<return_type>(
1599-
internal::invoke_argument::AdlTag(),
1600-
::std::get<k>(args), p0, p1);
1524+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1525+
::std::get<k>(args), p0, p1);
16011526
}
16021527

16031528
ACTION_TEMPLATE(InvokeArgument,
16041529
HAS_1_TEMPLATE_PARAMS(int, k),
16051530
AND_3_VALUE_PARAMS(p0, p1, p2)) {
16061531
using internal::invoke_argument::InvokeArgumentAdl;
1607-
return InvokeArgumentAdl<return_type>(
1608-
internal::invoke_argument::AdlTag(),
1609-
::std::get<k>(args), p0, p1, p2);
1532+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1533+
::std::get<k>(args), p0, p1, p2);
16101534
}
16111535

16121536
ACTION_TEMPLATE(InvokeArgument,
16131537
HAS_1_TEMPLATE_PARAMS(int, k),
16141538
AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
16151539
using internal::invoke_argument::InvokeArgumentAdl;
1616-
return InvokeArgumentAdl<return_type>(
1617-
internal::invoke_argument::AdlTag(),
1618-
::std::get<k>(args), p0, p1, p2, p3);
1540+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1541+
::std::get<k>(args), p0, p1, p2, p3);
16191542
}
16201543

16211544
ACTION_TEMPLATE(InvokeArgument,
16221545
HAS_1_TEMPLATE_PARAMS(int, k),
16231546
AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
16241547
using internal::invoke_argument::InvokeArgumentAdl;
1625-
return InvokeArgumentAdl<return_type>(
1626-
internal::invoke_argument::AdlTag(),
1627-
::std::get<k>(args), p0, p1, p2, p3, p4);
1548+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1549+
::std::get<k>(args), p0, p1, p2, p3, p4);
16281550
}
16291551

16301552
ACTION_TEMPLATE(InvokeArgument,
16311553
HAS_1_TEMPLATE_PARAMS(int, k),
16321554
AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
16331555
using internal::invoke_argument::InvokeArgumentAdl;
1634-
return InvokeArgumentAdl<return_type>(
1635-
internal::invoke_argument::AdlTag(),
1636-
::std::get<k>(args), p0, p1, p2, p3, p4, p5);
1556+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1557+
::std::get<k>(args), p0, p1, p2, p3, p4, p5);
16371558
}
16381559

16391560
ACTION_TEMPLATE(InvokeArgument,
16401561
HAS_1_TEMPLATE_PARAMS(int, k),
16411562
AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
16421563
using internal::invoke_argument::InvokeArgumentAdl;
1643-
return InvokeArgumentAdl<return_type>(
1644-
internal::invoke_argument::AdlTag(),
1645-
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
1564+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1565+
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
16461566
}
16471567

16481568
ACTION_TEMPLATE(InvokeArgument,
16491569
HAS_1_TEMPLATE_PARAMS(int, k),
16501570
AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
16511571
using internal::invoke_argument::InvokeArgumentAdl;
1652-
return InvokeArgumentAdl<return_type>(
1653-
internal::invoke_argument::AdlTag(),
1654-
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
1572+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1573+
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
16551574
}
16561575

16571576
ACTION_TEMPLATE(InvokeArgument,
16581577
HAS_1_TEMPLATE_PARAMS(int, k),
16591578
AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
16601579
using internal::invoke_argument::InvokeArgumentAdl;
1661-
return InvokeArgumentAdl<return_type>(
1662-
internal::invoke_argument::AdlTag(),
1663-
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
1580+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1581+
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7,
1582+
p8);
16641583
}
16651584

16661585
ACTION_TEMPLATE(InvokeArgument,
16671586
HAS_1_TEMPLATE_PARAMS(int, k),
16681587
AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
16691588
using internal::invoke_argument::InvokeArgumentAdl;
1670-
return InvokeArgumentAdl<return_type>(
1671-
internal::invoke_argument::AdlTag(),
1672-
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
1589+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
1590+
::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7,
1591+
p8, p9);
16731592
}
16741593

16751594
// Various overloads for ReturnNew<T>().

googlemock/include/gmock/gmock-generated-actions.h.pump

+2-29
Original file line numberDiff line numberDiff line change
@@ -506,32 +506,6 @@ namespace testing {
506506
// InvokeArgument action from temporary values and have it performed
507507
// later.
508508

509-
namespace internal {
510-
namespace invoke_argument {
511-
512-
// Appears in InvokeArgumentAdl's argument list to help avoid
513-
// accidental calls to user functions of the same name.
514-
struct AdlTag {};
515-
516-
// InvokeArgumentAdl - a helper for InvokeArgument.
517-
// The basic overloads are provided here for generic functors.
518-
// Overloads for other custom-callables are provided in the
519-
// internal/custom/gmock-generated-actions.h header.
520-
521-
$range i 0..n
522-
$for i
523-
[[
524-
$range j 1..i
525-
526-
template <typename R, typename F[[$for j [[, typename A$j]]]]>
527-
R InvokeArgumentAdl(AdlTag, F f[[$for j [[, A$j a$j]]]]) {
528-
return f([[$for j, [[a$j]]]]);
529-
}
530-
]]
531-
532-
} // namespace invoke_argument
533-
} // namespace internal
534-
535509
$range i 0..n
536510
$for i [[
537511
$range j 0..i-1
@@ -540,9 +514,8 @@ ACTION_TEMPLATE(InvokeArgument,
540514
HAS_1_TEMPLATE_PARAMS(int, k),
541515
AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])) {
542516
using internal::invoke_argument::InvokeArgumentAdl;
543-
return InvokeArgumentAdl<return_type>(
544-
internal::invoke_argument::AdlTag(),
545-
::std::get<k>(args)$for j [[, p$j]]);
517+
return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
518+
::std::get<k>(args)$for j[[, p$j]]);
546519
}
547520

548521
]]

0 commit comments

Comments
 (0)