template<class... Ts>
minilua::overloaded struct

Overloading trick to make functions take multiple overloaded lambdas.

Contents

Overloading trick for function that take lambdas where the parameter types can be different.

This is easier than writing

if constexpr (std::is_same_v<decltype(param), T>) { ... }

inside the lambda.

Usage:

std::visit(
    overloaded{
       [](int i) {
           std::cout << "This is an int " << i << "\n";
       },
       [](std::string s) {
           std::cout << "This is a string " << s << "\n";
       },
    },
    some_variant
);

Source: https://dev.to/tmr232/that-overloaded-trick-overloading-lambdas-in-c17