Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::experi...onal::value(3)  C++ Standard Libary std::experi...onal::value(3)

NAME
       std::experimental::optional::value - std::experimental::optional::value

Synopsis
	  constexpr T& value() &;		(1) (library fundamentals TS)
	  constexpr const T & value() const &;
	  constexpr T&&	value()	&&;		(2) (library fundamentals TS)
	  constexpr const T&& value() const &&;

	  Returns the contained	value.

	  1)  Equivalent to return bool(*this) ? *val :	throw bad_optional_ac-
       cess();.
	  2) Equivalent	to return bool(*this) ?	std::move(*val)	: throw
	  bad_optional_access();.

Parameters
	  (none)

Return value
	  A reference to the contained value.

Exceptions
	  std::experimental::bad_optional_access if *this does not  contain  a
       value.

Notes
	  The dereference operator operator*() does not	check if this optional
       contains	a
	  value, which may be more efficient than value().

Example
       // Run this code

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

	int main()
	{
	    std::experimental::optional<int> opt = {};

	    try
	    {
		int n =	opt.value();
	    }
	    catch (const std::logic_error& e)
	    {
		std::cout << e.what() << '\n';
	    }
	}

Possible output:
	optional<T>::value: not	engaged

See also
				    returns  the contained value if available,
       another value
	  value_or		    otherwise
				    (public member function)
	  operator->		    accesses the contained value
	  operator*		    (public member function)
	  bad_optional_access	    exception indicating checked access	to  an
       optional	that
	  (library fundamentals	TS) doesn't contain a value
				    (class)

Category:
	    * Noindexed	pages

http://cppreference.com		  2024.06.10	  std::experi...onal::value(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::experimental::optional::value&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help