GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::variant::index(3) C++ Standard Libary std::variant::index(3)

std::variant::index - std::variant::index


constexpr std::size_t index() const noexcept; (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.

// Run this code


#include <variant>
#include <string>
#include <iostream>
int main()
{
std::variant<int, std::string> v = "abc";


std::cout << "v.index = " << v.index() << '\n';


v = {};


std::cout << "v.index = " << v.index() << '\n';
}


v.index = 1
v.index = 0


holds_alternative checks if a variant currently holds a given type
(C++17) (function template)
std::get(std::variant) reads the value of the variant given the index or the type
(C++17) (if the type is unique), throws on error
(function template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.