Skip to content

Commit e32d1eb

Browse files
Abseil Teamcopybara-github
authored andcommitted
Make AnyInvocable remember more information
Add an extra variant to FunctionToCall: `relocate_from_to_and_query_rust`. It is identical to "relocate_from_to" for C++ managers, but instructs Rust managers to perform a special operation that can be detected by the caller. PiperOrigin-RevId: 837257408 Change-Id: Idc270af2716252612a77a26b1b3cf83778aaa20d
1 parent 18bd00a commit e32d1eb

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

absl/functional/internal/any_invocable.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,18 @@ using ForwardedParameterType = typename ForwardedParameter<T>::type;
159159
// A discriminator when calling the "manager" function that describes operation
160160
// type-erased operation should be invoked.
161161
//
162+
// "dispose" specifies that the manager should perform a destroy.
163+
//
162164
// "relocate_from_to" specifies that the manager should perform a move.
163165
//
164-
// "dispose" specifies that the manager should perform a destroy.
165-
enum class FunctionToCall : bool { relocate_from_to, dispose };
166+
// "relocate_from_to_and_query_rust" is identical to "relocate_from_to" for C++
167+
// managers, but instructs Rust managers to perform a special operation that
168+
// can be detected by the caller.
169+
enum class FunctionToCall : unsigned char {
170+
dispose,
171+
relocate_from_to,
172+
relocate_from_to_and_query_rust,
173+
};
166174

167175
// The portion of `AnyInvocable` state that contains either a pointer to the
168176
// target object or the object itself in local storage
@@ -243,6 +251,7 @@ void LocalManagerNontrivial(FunctionToCall operation,
243251

244252
switch (operation) {
245253
case FunctionToCall::relocate_from_to:
254+
case FunctionToCall::relocate_from_to_and_query_rust:
246255
// NOTE: Requires that the left-hand operand is already empty.
247256
::new (static_cast<void*>(&to->storage)) T(std::move(from_object));
248257
ABSL_FALLTHROUGH_INTENDED;
@@ -277,6 +286,7 @@ inline void RemoteManagerTrivial(FunctionToCall operation,
277286
TypeErasedState* const to) noexcept {
278287
switch (operation) {
279288
case FunctionToCall::relocate_from_to:
289+
case FunctionToCall::relocate_from_to_and_query_rust:
280290
// NOTE: Requires that the left-hand operand is already empty.
281291
to->remote = from->remote;
282292
return;
@@ -303,6 +313,7 @@ void RemoteManagerNontrivial(FunctionToCall operation,
303313

304314
switch (operation) {
305315
case FunctionToCall::relocate_from_to:
316+
case FunctionToCall::relocate_from_to_and_query_rust:
306317
// NOTE: Requires that the left-hand operand is already empty.
307318
to->remote.target = from->remote.target;
308319
return;

0 commit comments

Comments
 (0)