summaryrefslogtreecommitdiff
path: root/absl/base/invoke_test.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-06-22 10:03:06 -0700
committerGravatar Mark Barolak <mbar@google.com>2020-06-22 14:04:24 -0400
commit10cb35e459f5ecca5b2ff107635da0bfa41011b4 (patch)
treed382b5929817af05d27c0e3e23c800c84e80e892 /absl/base/invoke_test.cc
parent4ccc0fce09836a25b474f4b1453146dae2c29f4d (diff)
Export of internal Abseil changes
-- b548087c24ae7c2c709e8040a118b5e312d18e2e by Derek Mauro <dmauro@google.com>: Remove the static initialization of global variables used by absl::Mutex as requested by Chromium PiperOrigin-RevId: 317676541 -- f198f5da1e966772efa978ba019bd23576899794 by Greg Miller <jgm@google.com>: fix: work around gcc-4.8 bug in disjunction See https://godbolt.org/z/i7-AmM for a repro of the bug. I realize that Abseil no longer supports gcc 4.8 officially (https://abseil.io/docs/cpp/platforms/platforms), but Cloud C++ still supports gcc 4.8 officially, and so it would be nice to get this simple fix in. fixes https://github.com/abseil/abseil-cpp/issues/718 PiperOrigin-RevId: 317484459 -- ed233f646530c6c0948213b643cc6919db1bee90 by Chris Kennelly <ckennelly@google.com>: Avoid determining the size of the duration unit at runtime. PiperOrigin-RevId: 317376300 -- 73d4011c17fcf747a990176924a7adc69d443533 by Greg Falcon <gfalcon@google.com>: Change spelling of internal detail from `Invoke`/`InvokeT` to `invoke`/`invoke_result_t`. This matches the spelling of the C++17 standard library names that perform the same operations. PiperOrigin-RevId: 317311527 GitOrigin-RevId: b548087c24ae7c2c709e8040a118b5e312d18e2e Change-Id: I131809ff0b92cfdb0d96dc94e94d9c6f751cb0ac
Diffstat (limited to 'absl/base/invoke_test.cc')
-rw-r--r--absl/base/invoke_test.cc136
1 files changed, 71 insertions, 65 deletions
diff --git a/absl/base/invoke_test.cc b/absl/base/invoke_test.cc
index 6aa613c9..bcdef36c 100644
--- a/absl/base/invoke_test.cc
+++ b/absl/base/invoke_test.cc
@@ -86,71 +86,73 @@ struct FlipFlop {
int member;
};
-// CallMaybeWithArg(f) resolves either to Invoke(f) or Invoke(f, 42), depending
+// CallMaybeWithArg(f) resolves either to invoke(f) or invoke(f, 42), depending
// on which one is valid.
template <typename F>
-decltype(Invoke(std::declval<const F&>())) CallMaybeWithArg(const F& f) {
- return Invoke(f);
+decltype(base_internal::invoke(std::declval<const F&>())) CallMaybeWithArg(
+ const F& f) {
+ return base_internal::invoke(f);
}
template <typename F>
-decltype(Invoke(std::declval<const F&>(), 42)) CallMaybeWithArg(const F& f) {
- return Invoke(f, 42);
+decltype(base_internal::invoke(std::declval<const F&>(), 42)) CallMaybeWithArg(
+ const F& f) {
+ return base_internal::invoke(f, 42);
}
TEST(InvokeTest, Function) {
- EXPECT_EQ(1, Invoke(Function, 3, 2));
- EXPECT_EQ(1, Invoke(&Function, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(Function, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Function, 3, 2));
}
TEST(InvokeTest, NonCopyableArgument) {
- EXPECT_EQ(42, Invoke(Sink, make_unique<int>(42)));
+ EXPECT_EQ(42, base_internal::invoke(Sink, make_unique<int>(42)));
}
TEST(InvokeTest, NonCopyableResult) {
- EXPECT_THAT(Invoke(Factory, 42), ::testing::Pointee(42));
+ EXPECT_THAT(base_internal::invoke(Factory, 42), ::testing::Pointee(42));
}
-TEST(InvokeTest, VoidResult) {
- Invoke(NoOp);
-}
+TEST(InvokeTest, VoidResult) { base_internal::invoke(NoOp); }
TEST(InvokeTest, ConstFunctor) {
- EXPECT_EQ(1, Invoke(ConstFunctor(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(ConstFunctor(), 3, 2));
}
TEST(InvokeTest, MutableFunctor) {
MutableFunctor f;
- EXPECT_EQ(1, Invoke(f, 3, 2));
- EXPECT_EQ(1, Invoke(MutableFunctor(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(f, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(MutableFunctor(), 3, 2));
}
TEST(InvokeTest, EphemeralFunctor) {
EphemeralFunctor f;
- EXPECT_EQ(1, Invoke(std::move(f), 3, 2));
- EXPECT_EQ(1, Invoke(EphemeralFunctor(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(std::move(f), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(EphemeralFunctor(), 3, 2));
}
TEST(InvokeTest, OverloadedFunctor) {
OverloadedFunctor f;
const OverloadedFunctor& cf = f;
- EXPECT_EQ("&", Invoke(f));
- EXPECT_EQ("& 42", Invoke(f, " 42"));
+ EXPECT_EQ("&", base_internal::invoke(f));
+ EXPECT_EQ("& 42", base_internal::invoke(f, " 42"));
+
+ EXPECT_EQ("const&", base_internal::invoke(cf));
+ EXPECT_EQ("const& 42", base_internal::invoke(cf, " 42"));
- EXPECT_EQ("const&", Invoke(cf));
- EXPECT_EQ("const& 42", Invoke(cf, " 42"));
+ EXPECT_EQ("&&", base_internal::invoke(std::move(f)));
- EXPECT_EQ("&&", Invoke(std::move(f)));
- EXPECT_EQ("&& 42", Invoke(std::move(f), " 42"));
+ OverloadedFunctor f2;
+ EXPECT_EQ("&& 42", base_internal::invoke(std::move(f2), " 42"));
}
TEST(InvokeTest, ReferenceWrapper) {
ConstFunctor cf;
MutableFunctor mf;
- EXPECT_EQ(1, Invoke(std::cref(cf), 3, 2));
- EXPECT_EQ(1, Invoke(std::ref(cf), 3, 2));
- EXPECT_EQ(1, Invoke(std::ref(mf), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(std::cref(cf), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(std::ref(cf), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(std::ref(mf), 3, 2));
}
TEST(InvokeTest, MemberFunction) {
@@ -158,58 +160,62 @@ TEST(InvokeTest, MemberFunction) {
std::unique_ptr<const Class> cp(new Class);
std::unique_ptr<volatile Class> vp(new Class);
- EXPECT_EQ(1, Invoke(&Class::Method, p, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::Method, p.get(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::Method, *p, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::RefMethod, p, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::RefMethod, p.get(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::RefMethod, *p, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::RefRefMethod, std::move(*p), 3, 2)); // NOLINT
- EXPECT_EQ(1, Invoke(&Class::NoExceptMethod, p, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::NoExceptMethod, p.get(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::NoExceptMethod, *p, 3, 2));
-
- EXPECT_EQ(1, Invoke(&Class::ConstMethod, p, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::ConstMethod, p.get(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::ConstMethod, *p, 3, 2));
-
- EXPECT_EQ(1, Invoke(&Class::ConstMethod, cp, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::ConstMethod, cp.get(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::ConstMethod, *cp, 3, 2));
-
- EXPECT_EQ(1, Invoke(&Class::VolatileMethod, p, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::VolatileMethod, p.get(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::VolatileMethod, *p, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::VolatileMethod, vp, 3, 2));
- EXPECT_EQ(1, Invoke(&Class::VolatileMethod, vp.get(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::VolatileMethod, *vp, 3, 2));
-
- EXPECT_EQ(1, Invoke(&Class::Method, make_unique<Class>(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::ConstMethod, make_unique<Class>(), 3, 2));
- EXPECT_EQ(1, Invoke(&Class::ConstMethod, make_unique<const Class>(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::Method, p, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::Method, p.get(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::Method, *p, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::RefMethod, p, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::RefMethod, p.get(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::RefMethod, *p, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::RefRefMethod, std::move(*p), 3,
+ 2)); // NOLINT
+ EXPECT_EQ(1, base_internal::invoke(&Class::NoExceptMethod, p, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::NoExceptMethod, p.get(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::NoExceptMethod, *p, 3, 2));
+
+ EXPECT_EQ(1, base_internal::invoke(&Class::ConstMethod, p, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::ConstMethod, p.get(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::ConstMethod, *p, 3, 2));
+
+ EXPECT_EQ(1, base_internal::invoke(&Class::ConstMethod, cp, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::ConstMethod, cp.get(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::ConstMethod, *cp, 3, 2));
+
+ EXPECT_EQ(1, base_internal::invoke(&Class::VolatileMethod, p, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::VolatileMethod, p.get(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::VolatileMethod, *p, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::VolatileMethod, vp, 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::VolatileMethod, vp.get(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::VolatileMethod, *vp, 3, 2));
+
+ EXPECT_EQ(1,
+ base_internal::invoke(&Class::Method, make_unique<Class>(), 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::ConstMethod, make_unique<Class>(),
+ 3, 2));
+ EXPECT_EQ(1, base_internal::invoke(&Class::ConstMethod,
+ make_unique<const Class>(), 3, 2));
}
TEST(InvokeTest, DataMember) {
std::unique_ptr<Class> p(new Class{42});
std::unique_ptr<const Class> cp(new Class{42});
- EXPECT_EQ(42, Invoke(&Class::member, p));
- EXPECT_EQ(42, Invoke(&Class::member, *p));
- EXPECT_EQ(42, Invoke(&Class::member, p.get()));
+ EXPECT_EQ(42, base_internal::invoke(&Class::member, p));
+ EXPECT_EQ(42, base_internal::invoke(&Class::member, *p));
+ EXPECT_EQ(42, base_internal::invoke(&Class::member, p.get()));
- Invoke(&Class::member, p) = 42;
- Invoke(&Class::member, p.get()) = 42;
+ base_internal::invoke(&Class::member, p) = 42;
+ base_internal::invoke(&Class::member, p.get()) = 42;
- EXPECT_EQ(42, Invoke(&Class::member, cp));
- EXPECT_EQ(42, Invoke(&Class::member, *cp));
- EXPECT_EQ(42, Invoke(&Class::member, cp.get()));
+ EXPECT_EQ(42, base_internal::invoke(&Class::member, cp));
+ EXPECT_EQ(42, base_internal::invoke(&Class::member, *cp));
+ EXPECT_EQ(42, base_internal::invoke(&Class::member, cp.get()));
}
TEST(InvokeTest, FlipFlop) {
FlipFlop obj = {42};
// This call could resolve to (obj.*&FlipFlop::ConstMethod)() or
// ((*obj).*&FlipFlop::ConstMethod)(). We verify that it's the former.
- EXPECT_EQ(42, Invoke(&FlipFlop::ConstMethod, obj));
- EXPECT_EQ(42, Invoke(&FlipFlop::member, obj));
+ EXPECT_EQ(42, base_internal::invoke(&FlipFlop::ConstMethod, obj));
+ EXPECT_EQ(42, base_internal::invoke(&FlipFlop::member, obj));
}
TEST(InvokeTest, SfinaeFriendly) {