Methods Associated with std::variant
Some methods associated with std::variant to provide different facilities. Some of them are as follows:
S.No |
Method |
Description |
---|---|---|
1 |
index() | Returns the index of the type of data stored in the variant. |
2 |
emplace() | In place construction of the value of the variant. |
3 |
holds_alternative() | Check if the given type of data is stored inside the variant at the given moment in time. |
4 |
get() | It retrieves the value of the given type or index from the variant. |
std::variant in C++ 17
In the world of modern C++ programming, the std::variant is a powerful tool that allows you to work with multiple data types in a flexible and type-safe manner. In this article, we will discuss std::variant and explore its fundamentals, applications, and benefits with practical code examples.
Prerequisites: C++ data types, functions, unions, and classes.
Contact Us