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

std::variant_npos - std::variant_npos


Defined in header <variant>
inline constexpr std::size_t variant_npos = -1; (since C++17)


This is a special value equal to the largest value representable by the type
std::size_t, used as the return value of index() when valueless_by_exception() is
true

// Run this code


#include <iostream>
#include <stdexcept>
#include <string>
#include <variant>


struct Demon
{
Demon(int) {}
Demon(const Demon&) { throw std::domain_error("copy ctor"); }
Demon& operator= (const Demon&) = default;
};


int main()
{
std::variant<int, Demon> var{42};
std::cout
<< std::boolalpha
<< "index == npos: " << (var.index() == std::variant_npos) << '\n';


try { var = Demon{666}; } catch (const std::domain_error& ex)
{
std::cout
<< "Exception: " << ex.what() << '\n'
<< "index == npos: " << (var.index() == std::variant_npos) << '\n'
<< "valueless: " << var.valueless_by_exception() << '\n';
}
}


index == npos: false
Exception: copy ctor
index == npos: true
valueless: true


returns the zero-based index of the alternative held by the
index variant
(public member function)
valueless_by_exception checks if the variant is in the invalid state
(public member function)

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.