summaryrefslogtreecommitdiff
path: root/absl/functional/function_ref.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/functional/function_ref.h')
-rw-r--r--absl/functional/function_ref.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/absl/functional/function_ref.h b/absl/functional/function_ref.h
index 6e03ac2e..f9779607 100644
--- a/absl/functional/function_ref.h
+++ b/absl/functional/function_ref.h
@@ -50,6 +50,7 @@
#include <functional>
#include <type_traits>
+#include "absl/base/attributes.h"
#include "absl/functional/internal/function_ref.h"
#include "absl/meta/type_traits.h"
@@ -68,7 +69,8 @@ class FunctionRef;
// An `absl::FunctionRef` is a lightweight wrapper to any invokable object with
// a compatible signature. Generally, an `absl::FunctionRef` should only be used
// as an argument type and should be preferred as an argument over a const
-// reference to a `std::function`.
+// reference to a `std::function`. `absl::FunctionRef` itself does not allocate,
+// although the wrapped invokable may.
//
// Example:
//
@@ -98,7 +100,8 @@ class FunctionRef<R(Args...)> {
public:
// Constructs a FunctionRef from any invokable type.
template <typename F, typename = EnableIfCompatible<const F&>>
- FunctionRef(const F& f) // NOLINT(runtime/explicit)
+ // NOLINTNEXTLINE(runtime/explicit)
+ FunctionRef(const F& f ABSL_ATTRIBUTE_LIFETIME_BOUND)
: invoker_(&absl::functional_internal::InvokeObject<F, R, Args...>) {
absl::functional_internal::AssertNonNull(f);
ptr_.obj = &f;
@@ -122,6 +125,7 @@ class FunctionRef<R(Args...)> {
// To help prevent subtle lifetime bugs, FunctionRef is not assignable.
// Typically, it should only be used as an argument type.
FunctionRef& operator=(const FunctionRef& rhs) = delete;
+ FunctionRef(const FunctionRef& rhs) = default;
// Call the underlying object.
R operator()(Args... args) const {