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

std::experimental::optional::value_or - std::experimental::optional::value_or


template< class U > (library fundamentals TS)
constexpr T value_or( U&& default_value ) const&;
template< class U > (library fundamentals TS)
constexpr T value_or( U&& default_value ) &&;


Returns the contained value if *this has a value, otherwise returns default_value.


1) Equivalent to bool(*this) ? **this :
static_cast<T>(std::forward<U>(default_value))
2) Equivalent to bool(*this) ? std::move(**this) :
static_cast<T>(std::forward<U>(default_value))


default_value - the value to use in case *this is empty


-
T must meet the requirements of CopyConstructible in order to use overload (1).
-
T must meet the requirements of MoveConstructible in order to use overload (2).
-
U&& must be convertible to T


The current value if *this has a value, or default_value otherwise.


Any exception thrown by the selected constructor of the return value T.

// Run this code


#include <experimental/optional>
#include <iostream>
#include <cstdlib>


std::experimental::optional<const char*> maybe_getenv(const char* n)
{
if(const char* x = std::getenv(n))
return x;
else
return {};
}
int main()
{
std::cout << maybe_getenv("MYPWD").value_or("(none)") << '\n';
}


(none)


value returns the contained value
(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.