Skip to content

convert single-call recursive lambdas to unnamed IIFEs - #245

Merged
cameroncuster merged 5 commits into
devfrom
refactor/single-call-lambdas-to-iife
Jul 19, 2026
Merged

convert single-call recursive lambdas to unnamed IIFEs#245
cameroncuster merged 5 commits into
devfrom
refactor/single-call-lambdas-to-iife

Conversation

@cameroncuster

Copy link
Copy Markdown
Member

What

Converts 7 single-call recursive this auto&& lambdas from named
lambdas into unnamed immediately-invoked function expressions (IIFEs).

The pattern in each case:

auto dfs = [&](this auto&& dfs, ...) { ... };
dfs(args);

becomes:

[&](this auto&& dfs, ...) { ... }(args);

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 the
redundant name, not the return type.

Verification

  • Repo clang-format dry-run passes on all 7 files.
  • All 14 affected .test.cpp files compile cleanly under both g++ and clang
    with the repo's flags.
  • Self-contained handmade stress tests (count_paths, edge_cd_small_trees)
    pass their internal asserts and exit 0.

Net: 18 insertions, 25 deletions.

cameroncuster and others added 5 commits July 19, 2026 13:43
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
@cameroncuster
cameroncuster merged commit cc0212b into dev Jul 19, 2026
8 checks passed
@cameroncuster
cameroncuster deleted the refactor/single-call-lambdas-to-iife branch July 19, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants