diff options
Diffstat (limited to 'absl/functional')
-rw-r--r-- | absl/functional/function_ref.h | 8 | ||||
-rw-r--r-- | absl/functional/function_ref_test.cc | 5 |
2 files changed, 13 insertions, 0 deletions
diff --git a/absl/functional/function_ref.h b/absl/functional/function_ref.h index 2b9139d3..96cece55 100644 --- a/absl/functional/function_ref.h +++ b/absl/functional/function_ref.h @@ -137,6 +137,14 @@ class FunctionRef<R(Args...)> { 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 } // namespace absl diff --git a/absl/functional/function_ref_test.cc b/absl/functional/function_ref_test.cc index c61117eb..c0211135 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<int() const> ref(Function); + EXPECT_EQ(1337, ref()); +} + int NoExceptFunction() noexcept { return 1337; } // TODO(jdennett): Add a test for noexcept member functions. |