How to make a safer C++ variant visitor, similar to switch statements?
The pattern that a lot of people use with C++17 / boost variants looks very similar to switch statements. For example: ( snippet from cppreference.com ) std::variant<int, long, double, std::string> v = ...; std::visit(overloaded { [](auto arg) { std::cout << arg << ' '; }, [](double arg) { std::cout << std::fixed << arg << ' '; }, [](const std::string& arg) { std::cout << std::quoted(arg) << ' '; }, }, v); The problem is when you put the wrong type in the visitor or change the variant signature, but forget to change the visitor. Instead of getting a compile error, you will have the wrong