Merge branch 'google:main' into master

This commit is contained in:
Anthony Graca 2022-01-26 23:10:23 -08:00 committed by GitHub
commit 87252bba8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -1079,9 +1079,9 @@ struct ReturnNewAction {
template <size_t k>
struct ReturnArgAction {
template <typename... Args>
auto operator()(const Args&... args) const ->
typename std::tuple_element<k, std::tuple<Args...>>::type {
return std::get<k>(std::tie(args...));
auto operator()(Args&&... args) const -> decltype(std::get<k>(
std::forward_as_tuple(std::forward<Args>(args)...))) {
return std::get<k>(std::forward_as_tuple(std::forward<Args>(args)...));
}
};

View File

@ -462,6 +462,12 @@ TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
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) {
int result = 0;
const Action<void(int n)> a1 = SaveArg<0>(&result);