[optional.syn] # 22 General utilities library [[utilities]](./#utilities) ## 22.5 Optional objects [[optional]](optional#syn) ### 22.5.2 Header synopsis [optional.syn] [🔗](#header:%3coptional%3e) // mostly freestanding#include // see [[compare.syn]](compare.syn "17.12.1 Header synopsis")namespace std {// [[optional.optional]](optional.optional "22.5.3 Class template optional"), class template optionaltemplateclass optional; // partially freestanding// [[optional.optional.ref]](optional.optional.ref "22.5.4 Partial specialization of optional for reference types"), partial specialization of optional for lvalue reference typestemplateclass optional; // partially freestandingtemplateconstexpr bool ranges::enable_view> = true; templateconstexpr auto format_kind> = range_format::disabled; templateconstexpr bool ranges::enable_borrowed_range> = true; templateconcept [*is-derived-from-optional*](#concept:is-derived-from-optional "22.5.2 Header synopsis [optional.syn]") = requires(const T& t) { // *exposition only*[](const optional&){ }(t); }; // [[optional.nullopt]](optional.nullopt "22.5.5 No-value state indicator"), no-value state indicatorstruct nullopt_t{*see below*}; inline constexpr nullopt_t nullopt(*unspecified*); // [[optional.bad.access]](optional.bad.access "22.5.6 Class bad_­optional_­access"), class bad_optional_accessclass bad_optional_access; // [[optional.relops]](optional.relops "22.5.7 Relational operators"), relational operatorstemplateconstexpr bool operator==(const optional&, const optional&); templateconstexpr bool operator!=(const optional&, const optional&); templateconstexpr bool operator<(const optional&, const optional&); templateconstexpr bool operator>(const optional&, const optional&); templateconstexpr bool operator<=(const optional&, const optional&); templateconstexpr bool operator>=(const optional&, const optional&); template U>constexpr compare_three_way_result_toperator<=>(const optional&, const optional&); // [[optional.nullops]](optional.nullops "22.5.8 Comparison with nullopt"), comparison with nullopttemplate constexpr bool operator==(const optional&, nullopt_t) noexcept; templateconstexpr strong_ordering operator<=>(const optional&, nullopt_t) noexcept; // [[optional.comp.with.t]](optional.comp.with.t "22.5.9 Comparison with T"), comparison with Ttemplate constexpr bool operator==(const optional&, const U&); template constexpr bool operator==(const T&, const optional&); template constexpr bool operator!=(const optional&, const U&); template constexpr bool operator!=(const T&, const optional&); template constexpr bool operator<(const optional&, const U&); template constexpr bool operator<(const T&, const optional&); template constexpr bool operator>(const optional&, const U&); template constexpr bool operator>(const T&, const optional&); template constexpr bool operator<=(const optional&, const U&); template constexpr bool operator<=(const T&, const optional&); template constexpr bool operator>=(const optional&, const U&); template constexpr bool operator>=(const T&, const optional&); templaterequires (![*is-derived-from-optional*](#concept:is-derived-from-optional "22.5.2 Header synopsis [optional.syn]")) && [three_way_comparable_with](cmp.concept#concept:three_way_comparable_with "17.12.4 Concept three_­way_­comparable [cmp.concept]")constexpr compare_three_way_result_toperator<=>(const optional&, const U&); // [[optional.specalg]](optional.specalg "22.5.10 Specialized algorithms"), specialized algorithmstemplateconstexpr void swap(optional&, optional&) noexcept(*see below*); templateconstexpr optional> make_optional(T&&); templateconstexpr optional make_optional(Args&&... args); templateconstexpr optional make_optional(initializer_list il, Args&&... args); // [[optional.hash]](optional.hash "22.5.11 Hash support"), hash supporttemplate struct hash; template struct hash>;}