Repository navigation
Conversation
std::function is copyable: copying it forks a stateful lambda's state, and it cannot hold move-only captures. MoveOnlyFunction is an alias of std::move_only_function where the standard library has it, and a minimal R(Args...) fallback for Apple's libc++, which lacks it. Tests: move-only capture, moving keeps one state, empty and nullptr comparison, reassignment; copy is rejected at compile time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
… tests The standard does not make std::move_only_function's move assignment noexcept, and MSVC's STL does not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
ThreadPool::dispatch(), dispatch_now_blocking() and try_dispatch_now() take a task that the pool owns until it runs, so it never needs to be copied. Taking MoveOnlyFunction lets a task capture move-only state and rules out forking a stateful task by accident. Callers that pass a lambda are unchanged; the two try_dispatch_now() callers that build the task first now build a MoveOnlyFunction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Upstream merged MoveOnlyFunction as PokemonAutomation#1810. Conflicts in MoveOnlyFunction_Tests.cpp, ComputerPrograms_UnitTestRunner.cpp and SourceFiles.cmake take main's (PokemonAutomation#1810's) versions; this branch's migration of the thread pool and its callers is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on
main, which now has MoveOnlyFunction from PokemonAutomation#1810; the diff shows only this change.Thread pool tasks are owned by the pool until they run, so
ThreadPoolnow takes them asMoveOnlyFunction<void()>instead ofstd::function<void()>.dispatch(),dispatch_now_blocking(),try_dispatch_now()andAsyncTask_Cpp's stored task switch toMoveOnlyFunction. A task can now capture move-only state, and can't be forked by an accidental copy.try_dispatch_now()callers that build the task first (SnapshotManager, SwShfind_sparkles) now build aMoveOnlyFunction.run_in_parallel()keepsconst std::function&: it calls the function from many threads through a const reference, whichMoveOnlyFunction<void(size_t)>doesn't allow.std::functionuses are left as they are.Testing
MoveOnlyFunction), Windows clang and Ubuntu (std::move_only_function).🤖 Generated with Claude Code
https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E