---
name: "std::experimental::optional"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::experimental::optional"
---

# std::experimental::optional(3)

Class template for optional values.

## NAME

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

## SYNOPSIS

\#include \<optional\>

### Public Types

using **value\_type**\

### Public Member Functions

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 = \_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, **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, 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, \_Up && \>, \_\_not\_\< is\_convertible\< \_Up &&, \_Tp \> \>, \_\_not\_\< \_\_converts\_from\_optional\< \_Tp, \_Up \> \> \>::value, bool \> = false\> constexpr **optional** (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... \_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.
