Accept one-shot callables in InvokeArgument.
PiperOrigin-RevId: 611467660 Change-Id: Ic89ffc986141bee61f835cb60088aee92eb8bad9
This commit is contained in:
		
				
					committed by
					
						
						Copybara-Service
					
				
			
			
				
	
			
			
			
						parent
						
							e15c5a51b8
						
					
				
				
					commit
					e4fdb87e76
				
			@@ -592,8 +592,9 @@ namespace internal {
 | 
			
		||||
// Overloads for other custom-callables are provided in the
 | 
			
		||||
// internal/custom/gmock-generated-actions.h header.
 | 
			
		||||
template <typename F, typename... Args>
 | 
			
		||||
auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) {
 | 
			
		||||
  return f(args...);
 | 
			
		||||
auto InvokeArgument(F &&f,
 | 
			
		||||
                    Args... args) -> decltype(std::forward<F>(f)(args...)) {
 | 
			
		||||
  return std::forward<F>(f)(args...);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <std::size_t index, typename... Params>
 | 
			
		||||
 
 | 
			
		||||
@@ -91,6 +91,10 @@ struct UnaryMoveOnlyFunctor : UnaryFunctor {
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
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())));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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.
 | 
			
		||||
TEST(InvokeArgumentTest, Function5) {
 | 
			
		||||
  Action<int(int (*)(int, int, int, int, int))> a =  // NOLINT
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user