From Jason Turner
Watch on YouTube

Summary

This episode demonstrates a simple yet powerful technique for printing std::variant values using generic lambdas and std::visit. Jason shows how to overcome the challenge of printing a runtime-determined type using a compile-time formatting mechanism. The approach leverages a generic lambda as a visitor that invokes std::print for each possible variant type, with the compiler automatically generating the appropriate function call for whichever type is actually stored in the variant at runtime.

Resources

Tags