Skip to content

Commit 186e2bc

Browse files
authored
Update 006_variant_get_if.cpp
1 parent 3bd55b0 commit 186e2bc

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

cpp_17/006_variant_get_if.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
1
1+
#include <variant>
2+
#include <iostream>
3+
4+
int main()
5+
{
6+
std::variant<int, float> v{12};
7+
8+
if(auto pval = std::get_if<int>(&v))
9+
std::cout << "variant value: " << *pval << '\n';
10+
else
11+
std::cout << "failed to get value!" << '\n';
12+
}

0 commit comments

Comments
 (0)