Files
2025-10-25 03:02:53 +03:00

4.7 KiB

[optional.syn]

22 General utilities library [utilities]

22.5 Optional objects [optional]

22.5.2 Header synopsis [optional.syn]

🔗

// mostly freestanding#include // see [compare.syn]namespace std {// [optional.optional], class template optionaltemplateclass optional; // partially freestanding// [optional.optional.ref], partial specialization of optional for lvalue reference typestemplateclass optional<T&>; // partially freestandingtemplateconstexpr bool ranges::enable_view<optional> = true; templateconstexpr auto format_kind<optional> = range_format::disabled; templateconstexpr bool ranges::enable_borrowed_range<optional<T&>> = true; templateconcept is-derived-from-optional = requires(const T& t) { // exposition only[](const optional&){ }(t); }; // [optional.nullopt], no-value state indicatorstruct nullopt_t{see below}; inline constexpr nullopt_t nullopt(unspecified); // [optional.bad.access], class bad_optional_accessclass bad_optional_access; // [optional.relops], relational operatorstemplate<class T, class U>constexpr bool operator==(const optional&, const optional&); template<class T, class U>constexpr bool operator!=(const optional&, const optional&); template<class T, class U>constexpr bool operator<(const optional&, const optional&); template<class T, class U>constexpr bool operator>(const optional&, const optional&); template<class T, class U>constexpr bool operator<=(const optional&, const optional&); template<class T, class U>constexpr bool operator>=(const optional&, const optional&); template<class T, three_way_comparable_with U>constexpr compare_three_way_result_t<T, U>operator<=>(const optional&, const optional&); // [optional.nullops], comparison with nullopttemplate constexpr bool operator==(const optional&, nullopt_t) noexcept; templateconstexpr strong_ordering operator<=>(const optional&, nullopt_t) noexcept; // [optional.comp.with.t], comparison with Ttemplate<class T, class U> constexpr bool operator==(const optional&, const U&); template<class T, class U> constexpr bool operator==(const T&, const optional&); template<class T, class U> constexpr bool operator!=(const optional&, const U&); template<class T, class U> constexpr bool operator!=(const T&, const optional&); template<class T, class U> constexpr bool operator<(const optional&, const U&); template<class T, class U> constexpr bool operator<(const T&, const optional&); template<class T, class U> constexpr bool operator>(const optional&, const U&); template<class T, class U> constexpr bool operator>(const T&, const optional&); template<class T, class U> constexpr bool operator<=(const optional&, const U&); template<class T, class U> constexpr bool operator<=(const T&, const optional&); template<class T, class U> constexpr bool operator>=(const optional&, const U&); template<class T, class U> constexpr bool operator>=(const T&, const optional&); template<class T, class U>requires (is-derived-from-optional) && three_way_comparable_with<T, U>constexpr compare_three_way_result_t<T, U>operator<=>(const optional&, const U&); // [optional.specalg], specialized algorithmstemplateconstexpr void swap(optional&, optional&) noexcept(see below); templateconstexpr optional<decay_t> make_optional(T&&); template<class T, class... Args>constexpr optional make_optional(Args&&... args); template<class T, class U, class... Args>constexpr optional make_optional(initializer_list il, Args&&... args); // [optional.hash], hash supporttemplate struct hash; template struct hash<optional>;}