Summary
In this episode, Jason revisits the implementation of visitors for std::visit when working with std::variant. He demonstrates three approaches: using a generic lambda for when all variant types share a common interface, creating a struct with multiple overloaded call operators for type-specific handling, and using a C++20 technique that combines variadic templates and inheritance to create a visitor from multiple lambdas. This modern approach leverages multiple C++ features like variadic templates, variadic using declarations, multiple inheritance, and class template argument deduction to create a clean and efficient visitor implementation.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[variant]75% match -
[temp.res.general]51% match -
[variant.visit]40% match