Change ReturnArg to use perfect forwarding of arguments (#3733)
				
					
				
			PiperOrigin-RevId: 424355706 Change-Id: I618e5574b4b2c56a343905c20d8cc6d2a70cbcd1
This commit is contained in:
		
				
					committed by
					
						
						Copybara-Service
					
				
			
			
				
	
			
			
			
						parent
						
							f45d5865ed
						
					
				
				
					commit
					0b7798b2fb
				
			@@ -1079,9 +1079,9 @@ struct ReturnNewAction {
 | 
				
			|||||||
template <size_t k>
 | 
					template <size_t k>
 | 
				
			||||||
struct ReturnArgAction {
 | 
					struct ReturnArgAction {
 | 
				
			||||||
  template <typename... Args>
 | 
					  template <typename... Args>
 | 
				
			||||||
  auto operator()(const Args&... args) const ->
 | 
					  auto operator()(Args&&... args) const -> decltype(std::get<k>(
 | 
				
			||||||
      typename std::tuple_element<k, std::tuple<Args...>>::type {
 | 
					      std::forward_as_tuple(std::forward<Args>(args)...))) {
 | 
				
			||||||
    return std::get<k>(std::tie(args...));
 | 
					    return std::get<k>(std::forward_as_tuple(std::forward<Args>(args)...));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -462,6 +462,12 @@ TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
 | 
				
			|||||||
  EXPECT_EQ("seven", a.Perform(std::make_tuple(5, 6, std::string("seven"), 8)));
 | 
					  EXPECT_EQ("seven", a.Perform(std::make_tuple(5, 6, std::string("seven"), 8)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(ReturnArgActionTest, WorksForNonConstRefArg0) {
 | 
				
			||||||
 | 
					  const Action<std::string&(std::string&)> a = ReturnArg<0>();
 | 
				
			||||||
 | 
					  std::string s = "12345";
 | 
				
			||||||
 | 
					  EXPECT_EQ(&s, &a.Perform(std::forward_as_tuple(s)));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(SaveArgActionTest, WorksForSameType) {
 | 
					TEST(SaveArgActionTest, WorksForSameType) {
 | 
				
			||||||
  int result = 0;
 | 
					  int result = 0;
 | 
				
			||||||
  const Action<void(int n)> a1 = SaveArg<0>(&result);
 | 
					  const Action<void(int n)> a1 = SaveArg<0>(&result);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user