diff --git a/absl/functional/function_ref.h b/absl/functional/function_ref.h index 2b9139d3741..96cece551b5 100644 --- a/absl/functional/function_ref.h +++ b/absl/functional/function_ref.h @@ -137,6 +137,14 @@ class FunctionRef { absl::functional_internal::Invoker invoker_; }; +// Allow const qualified function signatures. Since FunctionRef requires +// constness anyway we can just make this a no-op. +template +class FunctionRef : public FunctionRef { + public: + using FunctionRef::FunctionRef; +}; + ABSL_NAMESPACE_END } // namespace absl diff --git a/absl/functional/function_ref_test.cc b/absl/functional/function_ref_test.cc index c61117eb8bd..c0211135a2b 100644 --- a/absl/functional/function_ref_test.cc +++ b/absl/functional/function_ref_test.cc @@ -47,6 +47,11 @@ TEST(FunctionRefTest, Function2) { EXPECT_EQ(1337, ref()); } +TEST(FunctionRefTest, ConstFunction) { + FunctionRef ref(Function); + EXPECT_EQ(1337, ref()); +} + int NoExceptFunction() noexcept { return 1337; } // TODO(jdennett): Add a test for noexcept member functions.