From Jason Turner
Watch on YouTube

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.

Resources

Tags