1) Index-based non-throwing accessor: If pv is not a null pointer and pv->index() == I, returns a pointer to the value stored in the variant pointed to by pv. Otherwise, returns a null pointer value. The call is ill-formed if I
is not a valid index in the variant.
2) Type-based non-throwing accessor: Equivalent to (1) with I
being the zero-based index of T
in Types.... The call is ill-formed if T
is not a unique element of Types....
Pointer to the value stored in the pointed-to variant or null pointer on error.
[edit] Example#include <iostream> #include <variant> int main() { auto check_value = [](const std::variant<int, float>& v) { if (const int* pval = std::get_if<int>(&v)) std::cout << "variant value: " << *pval << '\n'; else std::cout << "failed to get value!" << '\n'; }; std::variant<int, float> v{12}, w{3.f}; check_value(v); check_value(w); }
Output:
variant value: 12 failed to get value![edit] See also reads the value of the variant given the index or the type (if the type is unique), throws on error
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4