---
name: "std::experimental::optional"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::experimental::optional/3cxx"
---

# std::experimental::optional(3cxx)

Class template for optional values.

## NAME

std::experimental::optional\< \_Tp \> - Class template for optional values.

## SYNOPSIS

`#include <optional>`

Inherits **std::\_Optional\_base\< \_Tp, bool, bool \>**, and \_Enable\_copy\_move\< is\_copy\_constructible\< \_Tp \>::value, \_\_and\_\< is\_copy\_constructible\< \_Tp \>, is\_copy\_assignable\< \_Tp \> \>::value, is\_move\_constructible\< \_Tp \>::value, \_\_and\_\< is\_move\_constructible\< \_Tp \>, is\_move\_assignable\< \_Tp \> \>::value, optional\< \_Tp \> \>.

### Public Types

**using** **value\_type** = \_Tp\

### Public Member Functions

template\<**typename** \_Up  = \_Tp, **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< **optional**\< \_Tp \>, **decay\_t**\< \_Up \> \> \>, **is\_constructible**\< \_Tp, \_Up && \>, **is\_convertible**\< \_Up &&, \_Tp \> \>::value, bool \>  = true\> constexpr **optional** (\_Up &&\_\_t)\
 template\<**typename** \_Up  = \_Tp, **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< **optional**\< \_Tp \>, **decay\_t**\< \_Up \> \> \>, **is\_constructible**\< \_Tp, \_Up && \>, \_\_not\_\< **is\_convertible**\< \_Up &&, \_Tp \> \> \>::value, bool \>  = false\> constexpr **optional** (\_Up &&\_\_t)\
 template\<**typename** \_Up , **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< \_Tp, \_Up \> \>, **is\_constructible**\< \_Tp, const \_Up & \>, **is\_convertible**\< const \_Up &, \_Tp \>, \_\_not\_\< **\_\_converts\_from\_optional**\< \_Tp, \_Up \> \> \>::value, bool \>  = true\> constexpr **optional** (const **optional**\< \_Up \> &\_\_t)\
 template\<**typename** \_Up , **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< \_Tp, \_Up \> \>, **is\_constructible**\< \_Tp, const \_Up & \>, \_\_not\_\< **is\_convertible**\< const \_Up &, \_Tp \> \>, \_\_not\_\< **\_\_converts\_from\_optional**\< \_Tp, \_Up \> \> \>::value, bool \>  = false\> constexpr **optional** (const **optional**\< \_Up \> &\_\_t)\
 template\<**typename** \_Up , **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< \_Tp, \_Up \> \>, **is\_constructible**\< \_Tp, \_Up && \>, **is\_convertible**\< \_Up &&, \_Tp \>, \_\_not\_\< **\_\_converts\_from\_optional**\< \_Tp, \_Up \> \> \>::value, bool \>  = true\> constexpr **optional** (**optional**\< \_Up \> &&\_\_t)\
 template\<**typename** \_Up , **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< \_Tp, \_Up \> \>, **is\_constructible**\< \_Tp, \_Up && \>, \_\_not\_\< **is\_convertible**\< \_Up &&, \_Tp \> \>, \_\_not\_\< **\_\_converts\_from\_optional**\< \_Tp, \_Up \> \> \>::value, bool \>  = false\> constexpr **optional** (**optional**\< \_Up \> &&\_\_t)\
 template\<typename... \_Args\> **enable\_if\_t**\< **is\_constructible**\< \_Tp, **\_Args** &&... \>::value \> **emplace** (**\_Args** &&... **\_\_args**)\
 template\<**typename** \_Up , typename... \_Args\> **enable\_if\_t**\< **is\_constructible**\< \_Tp, **initializer\_list**\< \_Up \> &, **\_Args** &&... \>::value \> **emplace** (**initializer\_list**\< \_Up \> **\_\_il**, **\_Args** &&... **\_\_args**)\
 constexpr **operator bool** () const noexcept\
 constexpr \_Tp & **operator\*** () &\
 constexpr \_Tp && **operator\*** () &&\
 constexpr const \_Tp & **operator\*** () const &\
 constexpr const \_Tp && **operator\*** () const &&\
 \_Tp \* **operator-\>** ()\
 constexpr const \_Tp \* **operator-\>** () const\
 template\<**typename** \_Up  = \_Tp\> **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< **optional**\< \_Tp \>, **decay\_t**\< \_Up \> \> \>, **is\_constructible**\< \_Tp, \_Up \>, \_\_not\_\< \_\_and\_\< **is\_scalar**\< \_Tp \>, **is\_same**\< \_Tp, **decay\_t**\< \_Up \> \> \> \>, **is\_assignable**\< \_Tp &, \_Up \> \>::value, **optional** & \> **operator=** (\_Up &&**\_\_u**)\
 template\<**typename** \_Up \> **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< \_Tp, \_Up \> \>, **is\_constructible**\< \_Tp, const \_Up & \>, **is\_assignable**\< \_Tp &, \_Up \>, \_\_not\_\< **\_\_converts\_from\_optional**\< \_Tp, \_Up \> \>, \_\_not\_\< **\_\_assigns\_from\_optional**\< \_Tp, \_Up \> \> \>::value, **optional** & \> **operator=** (const **optional**\< \_Up \> &**\_\_u**)\
 **optional** & **operator=** (**nullopt\_t**) noexcept\
 template\<**typename** \_Up \> **enable\_if\_t**\< \_\_and\_\< \_\_not\_\< **is\_same**\< \_Tp, \_Up \> \>, **is\_constructible**\< \_Tp, \_Up \>, **is\_assignable**\< \_Tp &, \_Up \>, \_\_not\_\< **\_\_converts\_from\_optional**\< \_Tp, \_Up \> \>, \_\_not\_\< **\_\_assigns\_from\_optional**\< \_Tp, \_Up \> \> \>::value, **optional** & \> **operator=** (**optional**\< \_Up \> &&**\_\_u**)\
 **void** **swap** (**optional** &\_\_other) noexcept(**is\_nothrow\_move\_constructible**\< \_Tp \>() &&**\_\_is\_nothrow\_swappable**\< \_Tp \>::value)\
 constexpr \_Tp & **value** () &\
 constexpr \_Tp && **value** () &&\
 constexpr const \_Tp & **value** () const &\
 constexpr const \_Tp && **value** () const &&\
 template\<**typename** \_Up \> \_Tp **value\_or** (\_Up &&**\_\_u**) &&\
 template\<**typename** \_Up \> constexpr \_Tp **value\_or** (\_Up &&**\_\_u**) const &\

## Detailed Description

### template\<typename \_Tp\>

class std::experimental::optional\< \_Tp \>"Class template for optional values.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
