1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/functional/invoke.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(FunctionalTest, Invoke) {
16 constexpr int add(int x) const { return i + x; }
21 // Note: The tests involving a std::reference_wrapper are not static_asserts,
22 // since std::reference_wrapper is not constexpr prior to C++20.
23 static_assert(base::invoke(&S::add, s, 2) == 3, "");
24 EXPECT_EQ(base::invoke(&S::add, std::ref(s), 2), 3);
25 static_assert(base::invoke(&S::add, &s, 3) == 4, "");
27 static_assert(base::invoke(&S::i, s) == 1, "");
28 EXPECT_EQ(base::invoke(&S::i, std::ref(s)), 1);
29 static_assert(base::invoke(&S::i, &s) == 1, "");
31 static_assert(base::invoke(std::plus<>(), 1, 2) == 3, "");