Commit e68f1412 by Abseil Team Committed by Copybara-Service

Allow const qualified FunctionRef instances. This allows the signature to be…

Allow const qualified FunctionRef instances. This allows the signature to be compatible with AnyInvokable for const uses.

PiperOrigin-RevId: 565682320
Change-Id: I924dadf110481e572bdb8af0111fa62d6f553d90
parent 9a592abd
...@@ -137,6 +137,14 @@ class FunctionRef<R(Args...)> { ...@@ -137,6 +137,14 @@ class FunctionRef<R(Args...)> {
absl::functional_internal::Invoker<R, Args...> invoker_; absl::functional_internal::Invoker<R, Args...> invoker_;
}; };
// Allow const qualified function signatures. Since FunctionRef requires
// constness anyway we can just make this a no-op.
template <typename R, typename... Args>
class FunctionRef<R(Args...) const> : public FunctionRef<R(Args...)> {
public:
using FunctionRef<R(Args...)>::FunctionRef;
};
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
...@@ -47,6 +47,11 @@ TEST(FunctionRefTest, Function2) { ...@@ -47,6 +47,11 @@ TEST(FunctionRefTest, Function2) {
EXPECT_EQ(1337, ref()); EXPECT_EQ(1337, ref());
} }
TEST(FunctionRefTest, ConstFunction) {
FunctionRef<int() const> ref(Function);
EXPECT_EQ(1337, ref());
}
int NoExceptFunction() noexcept { return 1337; } int NoExceptFunction() noexcept { return 1337; }
// TODO(jdennett): Add a test for noexcept member functions. // TODO(jdennett): Add a test for noexcept member functions.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment