W3cubDocs

/C++

Standard library header <optional>

Classes

Name Description
(since C++17)
a wrapper that may or may not hold an object
(class template)
exception indicating checked access to an optional that doesn't contain a value
(class)
specializes the std::hash algorithm
(class template specialization)
(C++17)
indicator of optional type with uninitialized state
(class)

Functions

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

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

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/header/optional