An overload helper combines several lambdas into one callable object. It inherits from each lambda and brings every operator() into scope, making it a convenient visitor for std::variant. section 9.3.5
The pattern has a small set of moving parts:
- C++17 requires a deduction guide; C++20 can deduce the types directly. section 9.3.5
Dispatching reel actions
auto RollMethod = Overload{ [](Hold) {}, [&reel](Nudge) { std::rotate(reel.begin(), reel.begin() + 1, reel.end()); }, [&reel, &random_fn](Spin) { std::rotate(reel.begin(), reel.begin() + random_fn(), reel.end()); } }; std::visit(RollMethod, opt); Each alternative receives its matching lambda, while a missing alternative becomes a compile-time error. section 9.3.5
