Standard library header <optional>

From cppreference.com
< cpp‎ | header

Contents

[edit] Classes

Template:cpp/utility/optional/dsc optional
Name Description
exception indicating checked access to an optional that doesn't contain a value
(class)
(C++17)
disambiguation tag type for in-place construction of optional types
(class)
specializes the std::hash algorithm
(class template specialization)
(C++17)
indicator of optional type with uninitialized state
(class)

[edit] Functions

Comparison
compares optional objects
(function template)
Specialized algorithms
specializes the std::swap algorithm
(function)
creates an optional object
(function template)

[edit] Synopsis

namespace std {
 
  template <class T> class optional;
 
  // In-place construction
  struct in_place_t{};
  constexpr in_place_t in_place{};
 
  // No-value state indicator
  struct nullopt_t{see below};
  constexpr nullopt_t nullopt(unspecified);
 
  // Class bad_optional_access
  class bad_optional_access;
 
  // Relational operators
  template <class T>
    constexpr bool operator==(const optional<T>&, const optional<T>&);
  template <class T>
    constexpr bool operator!=(const optional<T>&, const optional<T>&);
  template <class T>
    constexpr bool operator<(const optional<T>&, const optional<T>&);
  template <class T>
    constexpr bool operator>(const optional<T>&, const optional<T>&);
  template <class T>
    constexpr bool operator<=(const optional<T>&, const optional<T>&);
  template <class T>
    constexpr bool operator>=(const optional<T>&, const optional<T>&);
 
  // Comparison with nullopt
  template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
  template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept;
  template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept;
  template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept;
  template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept;
  template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept;
  template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept;
  template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept;
  template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept;
  template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept;
  template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept;
  template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept;
 
  // Comparison with T
  template <class T> constexpr bool operator==(const optional<T>&, const T&);
  template <class T> constexpr bool operator==(const T&, const optional<T>&);
  template <class T> constexpr bool operator!=(const optional<T>&, const T&);
  template <class T> constexpr bool operator!=(const T&, const optional<T>&);
  template <class T> constexpr bool operator<(const optional<T>&, const T&);
  template <class T> constexpr bool operator<(const T&, const optional<T>&);
  template <class T> constexpr bool operator<=(const optional<T>&, const T&);
  template <class T> constexpr bool operator<=(const T&, const optional<T>&);
  template <class T> constexpr bool operator>(const optional<T>&, const T&);
  template <class T> constexpr bool operator>(const T&, const optional<T>&);
  template <class T> constexpr bool operator>=(const optional<T>&, const T&);
  template <class T> constexpr bool operator>=(const T&, const optional<T>&);
 
  //Specialized algorithms
  template <class T> void swap(optional<T>&, optional<T>&) noexcept(see below);
  template <class T> constexpr optional<see below> make_optional(T&&);
 
  // Hash support
  template <class T> struct hash;
  template <class T> struct hash<experimental::optional<T>>;
 
} // namespace std