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::holds_alternative(3) C++ Standard Libary std::holds_alternative(3)

std::holds_alternative - std::holds_alternative


Defined in header <variant>
template< class T, class... Types >
constexpr bool holds_alternative( const std::variant<Types...>& v ) (since C++17)
noexcept;


Checks if the variant v holds the alternative T. The call is ill-formed if T does
not appear exactly once in Types...


v - variant to examine


true if the variant currently holds the alternative T, false otherwise.

// Run this code


#include <variant>
#include <string>
#include <iostream>
int main()
{
std::variant<int, std::string> v = "abc";
std::cout << std::boolalpha
<< "variant holds int? "
<< std::holds_alternative<int>(v) << '\n'
<< "variant holds string? "
<< std::holds_alternative<std::string>(v) << '\n';
}


variant holds int? false
variant holds string? true


returns the zero-based index of the alternative held by the
index variant
(public member function)
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.