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

std::any::has_value - std::any::has_value


bool has_value() const noexcept; (since C++17)


Checks whether the object contains a value.


(none)


true if instance contains a value, otherwise false.

// Run this code


#include <any>
#include <iostream>
#include <string>


int main()
{
std::boolalpha(std::cout);


std::any a0;
std::cout << "a0.has_value(): " << a0.has_value() << "\n";


std::any a1 = 42;
std::cout << "a1.has_value(): " << a1.has_value() << '\n';
std::cout << "a1 = " << std::any_cast<int>(a1) << '\n';
a1.reset();
std::cout << "a1.has_value(): " << a1.has_value() << '\n';


auto a2 = std::make_any<std::string>("Milky Way");
std::cout << "a2.has_value(): " << a2.has_value() << '\n';
std::cout << "a2 = \"" << std::any_cast<std::string&>(a2) << "\"\n";
a2.reset();
std::cout << "a2.has_value(): " << a2.has_value() << '\n';
}


a0.has_value(): false
a1.has_value(): true
a1 = 42
a1.has_value(): false
a2.has_value(): true
a2 = "Milky Way"
a2.has_value(): false


reset destroys contained object
(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.