diff options
author | Benjamin Barenblat <bbaren@google.com> | 2024-09-03 11:49:29 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2024-09-03 11:49:29 -0400 |
commit | c1afa8b8238c25591ca80d068477aa7d4ce05fc8 (patch) | |
tree | 284a9f8b319de5783ff83ad004a9e390cb60fd0d /absl/functional/any_invocable.h | |
parent | 23778b53f420f54eebc195dd8430e79bda165e5b (diff) | |
parent | 4447c7562e3bc702ade25105912dce503f0c4010 (diff) |
Merge new upstream LTS 20240722.0
Diffstat (limited to 'absl/functional/any_invocable.h')
-rw-r--r-- | absl/functional/any_invocable.h | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/absl/functional/any_invocable.h b/absl/functional/any_invocable.h index 68d88253..3acb9fd0 100644 --- a/absl/functional/any_invocable.h +++ b/absl/functional/any_invocable.h @@ -34,6 +34,7 @@ #define ABSL_FUNCTIONAL_ANY_INVOCABLE_H_ #include <cstddef> +#include <functional> #include <initializer_list> #include <type_traits> #include <utility> @@ -98,9 +99,9 @@ ABSL_NAMESPACE_BEGIN // `AnyInvocable` also properly respects `const` qualifiers, reference // qualifiers, and the `noexcept` specification (only in C++ 17 and beyond) as // part of the user-specified function type (e.g. -// `AnyInvocable<void()&& const noexcept>`). These qualifiers will be applied to -// the `AnyInvocable` object's `operator()`, and the underlying invocable must -// be compatible with those qualifiers. +// `AnyInvocable<void() const && noexcept>`). These qualifiers will be applied +// to the `AnyInvocable` object's `operator()`, and the underlying invocable +// must be compatible with those qualifiers. // // Comparison of const and non-const function types: // @@ -151,6 +152,12 @@ ABSL_NAMESPACE_BEGIN // // Attempting to call `absl::AnyInvocable` multiple times in such a case // results in undefined behavior. +// +// Invoking an empty `absl::AnyInvocable` results in undefined behavior: +// +// // Create an empty instance using the default constructor. +// AnyInvocable<void()> empty; +// empty(); // WARNING: Undefined behavior! template <class Sig> class AnyInvocable : private internal_any_invocable::Impl<Sig> { private: @@ -167,6 +174,7 @@ class AnyInvocable : private internal_any_invocable::Impl<Sig> { // Constructors // Constructs the `AnyInvocable` in an empty state. + // Invoking it results in undefined behavior. AnyInvocable() noexcept = default; AnyInvocable(std::nullptr_t) noexcept {} // NOLINT @@ -277,6 +285,8 @@ class AnyInvocable : private internal_any_invocable::Impl<Sig> { // In other words: // std::function<void()> f; // empty // absl::AnyInvocable<void()> a = std::move(f); // not empty + // + // Invoking an empty `AnyInvocable` results in undefined behavior. explicit operator bool() const noexcept { return this->HasValue(); } // Invokes the target object of `*this`. `*this` must not be empty. |