Returns the zero-based index of the alternative that is currently held by the variant.
If the variant is valueless_by_exception
, returns variant_npos
.
#include <iostream> #include <string> #include <variant> int main() { std::variant<int, std::string> v = "abc"; std::cout << "v.index = " << v.index() << '\n'; v = {}; std::cout << "v.index = " << v.index() << '\n'; }
Output:
[edit] See also checks if avariant
currently holds a given type
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