22
General utilities library
[utilities]
22.5
Optional objects
[optional]
22.5.2
Header
<optional>
synopsis
[optional.syn]
🔗
#include
<
compare
>
// see
[compare.
syn]
namespace
std
{
//
[optional.
optional]
, class template
optional
template
<
class
T
>
class
optional;
template
<
class
T
>
concept
is-derived-from-optional
=
requires
(
const
T
&
t
)
{
//
exposition only
[
]
<
class
U
>
(
const
optional
<
U
>
&
)
{
}
(
t
)
;
}
;
//
[optional.
nullopt]
, no-value state indicator
struct
nullopt_t
{
see below
}
;
inline
constexpr
nullopt_t nullopt
(
unspecified
)
;
//
[optional.
bad.
access]
, class
bad_
optional_
access
class
bad_optional_access;
//
[optional.
relops]
, relational operators
template
<
class
T,
class
U
>
constexpr
bool
operator
=
=
(
const
optional
<
T
>
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
!
=
(
const
optional
<
T
>
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
<
(
const
optional
<
T
>
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
>
(
const
optional
<
T
>
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
<
=
(
const
optional
<
T
>
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
>
=
(
const
optional
<
T
>
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
three_
way_
comparable_
with
<
T
>
U
>
constexpr
compare_three_way_result_t
<
T, U
>
operator
<
=
>
(
const
optional
<
T
>
&
,
const
optional
<
U
>
&
)
;
//
[optional.
nullops]
, comparison with
nullopt
template
<
class
T
>
constexpr
bool
operator
=
=
(
const
optional
<
T
>
&
, nullopt_t
)
noexcept
;
template
<
class
T
>
constexpr
strong_ordering
operator
<
=
>
(
const
optional
<
T
>
&
, nullopt_t
)
noexcept
;
//
[optional.
comp.
with.
t]
, comparison with
T
template
<
class
T,
class
U
>
constexpr
bool
operator
=
=
(
const
optional
<
T
>
&
,
const
U
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
=
=
(
const
T
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
!
=
(
const
optional
<
T
>
&
,
const
U
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
!
=
(
const
T
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
<
(
const
optional
<
T
>
&
,
const
U
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
<
(
const
T
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
>
(
const
optional
<
T
>
&
,
const
U
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
>
(
const
T
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
<
=
(
const
optional
<
T
>
&
,
const
U
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
<
=
(
const
T
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
>
=
(
const
optional
<
T
>
&
,
const
U
&
)
;
template
<
class
T,
class
U
>
constexpr
bool
operator
>
=
(
const
T
&
,
const
optional
<
U
>
&
)
;
template
<
class
T,
class
U
>
requires
(
!
is-derived-from-optional
<
U
>
)
&
&
three_
way_
comparable_
with
<
T, U
>
constexpr
compare_three_way_result_t
<
T, U
>
operator
<
=
>
(
const
optional
<
T
>
&
,
const
U
&
)
;
//
[optional.
specalg]
, specialized algorithms
template
<
class
T
>
constexpr
void
swap
(
optional
<
T
>
&
, optional
<
T
>
&
)
noexcept
(
see below
)
;
template
<
class
T
>
constexpr
optional
<
see below
>
make_optional
(
T
&
&
)
;
template
<
class
T,
class
.
.
.
Args
>
constexpr
optional
<
T
>
make_optional
(
Args
&
&
.
.
.
args
)
;
template
<
class
T,
class
U,
class
.
.
.
Args
>
constexpr
optional
<
T
>
make_optional
(
initializer_list
<
U
>
il, Args
&
&
.
.
.
args
)
;
//
[optional.
hash]
, hash support
template
<
class
T
>
struct
hash;
template
<
class
T
>
struct
hash
<
optional
<
T
>
>
;
}