convert single-call recursive lambdas to unnamed IIFEs - #245
Merged
Conversation
For the 7 library files where a `this auto&&` recursive lambda is defined and invoked exactly once, drop the name and immediately invoke the lambda in place. This removes a redundant binding without changing behavior. Note: explicit return types are retained where present, since C++ cannot deduce the return type of a recursive lambda whose recursive call precedes any return. Verified: repo clang-format passes; all affected tests compile under both g++ and clang; self-contained handmade stress tests pass at runtime.
Per convention, name the `this auto&&` recursion parameter of the unnamed IIFEs `self` (previously `dfs`/`dnc`). Updates the parameter and all recursive call sites within each of the 7 IIFEs. No behavior change.
…ambdas-to-iife # Conflicts: # .verify-helper/timestamps.remote.json
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.
What
Converts 7 single-call recursive
this auto&&lambdas from namedlambdas into unnamed immediately-invoked function expressions (IIFEs).
The pattern in each case:
becomes:
Files
library/convolution/min_plus_convolution_convex_and_arbitrary.hpp(dnc)library/graphs/euler_path.hpp(dfs)library/graphs/strongly_connected_components/offline_incremental_scc.hpp(dnc)library/trees/centroid_decomp.hpp(dfs)library/trees/edge_cd.hpp(dfs)library/trees/shallowest_decomp_tree.hpp(dfs)library/trees/uncommon/subtree_isomorphism.hpp(dfs)For
centroid_decomp.hpp, the comma-operator return (return dfs(0), p;)was cleaned into a discarded IIFE statement followed by
return p;—semantically identical and formats cleanly.
Note
Explicit return types (
-> int,-> void) are retained where present.C++ cannot deduce the return type of a recursive lambda whose recursive
call precedes any
return, so the IIFE conversion only removes theredundant name, not the return type.
Verification
.test.cppfiles compile cleanly under both g++ and clangwith the repo's flags.
count_paths,edge_cd_small_trees)pass their internal asserts and exit 0.
Net: 18 insertions, 25 deletions.