The callback factory worked perfectly through the entire demo sprint. In prod the counters started returning numbers from a parallel universe — only under load, and only on Fridays. A genre classic: the lambda captured a local by reference and outlived it. A closure should own its state, not sublet someone else's stack.
makeCounter returns a lambda that captures the local count by reference — but count dies when makeCounter returns. Every later call reads and writes a dead stack slot (undefined behaviour). Fix the capture.
makeCounter() calls are independentmutable keyword?Capture by value: [count]. The closure then owns its own copy of the counter.
By-value captures are const inside the call operator by default — add mutable: [count]() mutable { return ++count; }.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.