File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -1455,6 +1455,30 @@ struct WithArgsAction {
1455
1455
return OA{std::move (inner_action)};
1456
1456
}
1457
1457
1458
+ // As above, but in the case where we want to create a OnceAction from a const
1459
+ // WithArgsAction. This is fine as long as the inner action doesn't need to
1460
+ // move any of its state to create a OnceAction.
1461
+ template <
1462
+ typename R, typename ... Args,
1463
+ typename std::enable_if<
1464
+ std::is_convertible<const InnerAction&,
1465
+ OnceAction<R(internal::TupleElement<
1466
+ I, std::tuple<Args...>>...)>>::value,
1467
+ int >::type = 0 >
1468
+ operator OnceAction<R(Args...)>() const & { // NOLINT
1469
+ struct OA {
1470
+ OnceAction<InnerSignature<R, Args...>> inner_action;
1471
+
1472
+ R operator ()(Args&&... args) && {
1473
+ return std::move (inner_action)
1474
+ .Call (std::get<I>(
1475
+ std::forward_as_tuple (std::forward<Args>(args)...))...);
1476
+ }
1477
+ };
1478
+
1479
+ return OA{inner_action};
1480
+ }
1481
+
1458
1482
template <
1459
1483
typename R, typename ... Args,
1460
1484
typename std::enable_if<
Original file line number Diff line number Diff line change @@ -1645,6 +1645,22 @@ TEST(WithArgsTest, RefQualifiedInnerAction) {
1645
1645
EXPECT_EQ (19 , mock.AsStdFunction ()(0 , 17 ));
1646
1646
}
1647
1647
1648
+ // It should be fine to provide an lvalue WithArgsAction to WillOnce, even when
1649
+ // the inner action only wants to convert to OnceAction.
1650
+ TEST (WithArgsTest, ProvideAsLvalueToWillOnce) {
1651
+ struct SomeAction {
1652
+ operator OnceAction<int (int )>() const { // NOLINT
1653
+ return [](const int arg) { return arg + 2 ; };
1654
+ }
1655
+ };
1656
+
1657
+ const auto wa = WithArg<1 >(SomeAction{});
1658
+
1659
+ MockFunction<int (int , int )> mock;
1660
+ EXPECT_CALL (mock, Call).WillOnce (wa);
1661
+ EXPECT_EQ (19 , mock.AsStdFunction ()(0 , 17 ));
1662
+ }
1663
+
1648
1664
#ifndef GTEST_OS_WINDOWS_MOBILE
1649
1665
1650
1666
class SetErrnoAndReturnTest : public testing ::Test {
You can’t perform that action at this time.
0 commit comments