A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../utility/variant/index.html below:

std::variant<Types...>::index - cppreference.com

(since C++17)

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.

[edit] Example
#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 a variant currently holds a given type
(function template) [edit] reads the value of the variant given the index or the type (if the type is unique), throws on error
(function template) [edit]

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