mirror of
https://github.com/google/googletest.git
synced 2024-12-27 02:01:25 +08:00
Accept one-shot callables in InvokeArgument.
PiperOrigin-RevId: 611467660 Change-Id: Ic89ffc986141bee61f835cb60088aee92eb8bad9
This commit is contained in:
parent
e15c5a51b8
commit
e4fdb87e76
@ -592,8 +592,9 @@ namespace internal {
|
|||||||
// Overloads for other custom-callables are provided in the
|
// Overloads for other custom-callables are provided in the
|
||||||
// internal/custom/gmock-generated-actions.h header.
|
// internal/custom/gmock-generated-actions.h header.
|
||||||
template <typename F, typename... Args>
|
template <typename F, typename... Args>
|
||||||
auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) {
|
auto InvokeArgument(F &&f,
|
||||||
return f(args...);
|
Args... args) -> decltype(std::forward<F>(f)(args...)) {
|
||||||
|
return std::forward<F>(f)(args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t index, typename... Params>
|
template <std::size_t index, typename... Params>
|
||||||
|
@ -91,6 +91,10 @@ struct UnaryMoveOnlyFunctor : UnaryFunctor {
|
|||||||
UnaryMoveOnlyFunctor(UnaryMoveOnlyFunctor&&) = default;
|
UnaryMoveOnlyFunctor(UnaryMoveOnlyFunctor&&) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct OneShotUnaryFunctor {
|
||||||
|
int operator()(bool x) && { return x ? 1 : -1; }
|
||||||
|
};
|
||||||
|
|
||||||
const char* Binary(const char* input, short n) { return input + n; } // NOLINT
|
const char* Binary(const char* input, short n) { return input + n; } // NOLINT
|
||||||
|
|
||||||
int Ternary(int x, char y, short z) { return x + y + z; } // NOLINT
|
int Ternary(int x, char y, short z) { return x + y + z; } // NOLINT
|
||||||
@ -716,6 +720,12 @@ TEST(InvokeArgumentTest, Functor1MoveOnly) {
|
|||||||
EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryMoveOnlyFunctor())));
|
EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryMoveOnlyFunctor())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests using InvokeArgument with a one-shot unary functor.
|
||||||
|
TEST(InvokeArgumentTest, OneShotFunctor1) {
|
||||||
|
Action<int(OneShotUnaryFunctor)> a = InvokeArgument<0>(true); // NOLINT
|
||||||
|
EXPECT_EQ(1, a.Perform(std::make_tuple(OneShotUnaryFunctor())));
|
||||||
|
}
|
||||||
|
|
||||||
// Tests using InvokeArgument with a 5-ary function.
|
// Tests using InvokeArgument with a 5-ary function.
|
||||||
TEST(InvokeArgumentTest, Function5) {
|
TEST(InvokeArgumentTest, Function5) {
|
||||||
Action<int(int (*)(int, int, int, int, int))> a = // NOLINT
|
Action<int(int (*)(int, int, int, int, int))> a = // NOLINT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user