15 #include "absl/base/internal/invoke.h"
22 #include "gmock/gmock.h"
23 #include "gtest/gtest.h"
24 #include "absl/memory/memory.h"
25 #include "absl/strings/str_cat.h"
29 namespace base_internal {
34 int Sink(std::unique_ptr<int> p) {
38 std::unique_ptr<int> Factory(
int n) {
39 return make_unique<int>(n);
45 int operator()(
int a,
int b)
const {
return a -
b; }
48 struct MutableFunctor {
49 int operator()(
int a,
int b) {
return a -
b; }
52 struct EphemeralFunctor {
53 int operator()(
int a,
int b) && {
return a -
b; }
56 struct OverloadedFunctor {
57 template <
typename...
Args>
61 template <
typename...
Args>
65 template <
typename...
Args>
72 int Method(
int a,
int b) {
return a -
b; }
73 int ConstMethod(
int a,
int b)
const {
return a -
b; }
74 int RefMethod(
int a,
int b) & {
return a -
b; }
75 int RefRefMethod(
int a,
int b) && {
return a -
b; }
76 int NoExceptMethod(
int a,
int b) noexcept {
return a -
b; }
77 int VolatileMethod(
int a,
int b)
volatile {
return a -
b; }
83 int ConstMethod()
const {
return member; }
108 TEST(InvokeTest, NonCopyableArgument) {
112 TEST(InvokeTest, NonCopyableResult) {
118 TEST(InvokeTest, ConstFunctor) {
122 TEST(InvokeTest, MutableFunctor) {
128 TEST(InvokeTest, EphemeralFunctor) {
134 TEST(InvokeTest, OverloadedFunctor) {
136 const OverloadedFunctor& cf =
f;
146 OverloadedFunctor
f2;
150 TEST(InvokeTest, ReferenceWrapper) {
158 TEST(InvokeTest, MemberFunction) {
159 std::unique_ptr<Class>
p(
new Class);
160 std::unique_ptr<const Class> cp(
new Class);
161 std::unique_ptr<volatile Class> vp(
new Class);
195 make_unique<const Class>(), 3, 2));
198 TEST(InvokeTest, DataMember) {
199 std::unique_ptr<Class>
p(
new Class{42});
200 std::unique_ptr<const Class> cp(
new Class{42});
213 TEST(InvokeTest, FlipFlop) {
221 TEST(InvokeTest, SfinaeFriendly) {
222 CallMaybeWithArg(
NoOp);