C++ variant is a type-safe union that can store a value of any type among its alternative types. The getType function in C++ variant returns the current type of the stored value.
For example, if we have a variant declared as follows:
std::variant var;
We can use the getType function to determine the current type of var:
if (var.index() == 0) { std::cout << "The stored type is int. Value = " << std::get(var) << std::endl; } else if (var.index() == 1) { std::cout << "The stored type is float. Value = " << std::get(var) << std::endl; } else if (var.index() == 2) { std::cout << "The stored type is std::string. Value = " << std::get(var) << std::endl; }
In this example, the getType function is used to determine the current type of the stored value in the variant. Depending on the current type, the code prints the value of the stored value.
This code example uses the C++ standard library package.
C++ (Cpp) Variant::GetType - 24 examples found. These are the top rated real world C++ (Cpp) examples of Variant::GetType from package rvtests extracted from open source projects. You can rate examples to help us improve the quality of examples.