boost::variant
variable, use the free-standing function boost::get()
.boost::get()
expects one of the valid types for the corresponding variable as a template parameter.
Features of Boost::get( ) Function:
Specifying an invalid type will result in a run-time error because validation of types does not take place at compile time.
Variables of type boost::variant
can be written to streams such as the standard output stream, bypassing the hazard of run-time errors
Code:
int main()
{
boost::variant<double, char, std::string> v;
v = 3.14;
std::cout << boost::get<double>(v) << '\n';
v = 'A';
std::cout << boost::get<char>(v) << '\n';
v = "Boost";
std::cout << boost::get<std::string>(v) << '\n';
}
Output
14.5
Z
Boost::get() function
Name | Views | Likes |
---|---|---|
C++ boost::Variant | 1851 | 1 |
C++ BOOST::ALGORITHM::IS_DIGIT( ) | 526 | 0 |
C++ BOOST ::STRING ALGO::TO_UPPER_COPY( ) | 502 | 1 |
C++::boost::variant::static_visitor | 1690 | 1 |
C++::Boost::Variant::get( ) | 2412 | 1 |
C++ PROGRAM TO FIND MAX SUBTREE SUM IN A TREE | 403 | 1 |
C++ BOOST::ALGORITHM::STRING COMPARE | 1604 | 1 |
C++::Boost::Variant::Apply_visitor( ) | 2266 | 1 |
C++ BOOST ::STRING ALGO::ERASE( ) | 780 | 1 |
C++ BOOST::ALGORITHM::REPLACE | 1221 | 0 |
C++ BOOST::ALGORITHM::FIND FUNCTION | 819 | 1 |
C++ Boost::variant::variant | 390 | 2 |
GSD | 331 | 7 |
C++ BOOST::ALGORITHM::TRIM | 1106 | 1 |
Comments