C++17 has granted us with std::variant. Simply put, it is a type-safe union. To access the value it stores, you can either request a specific type (using std::get or something similar) or “visit” the variant, automatically handling only the data-type that is actually there. Visiting is done using std::visit, and is fairly straight forward. Compilation, Execution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include #include #include using var_t = std::variant; // (...