Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::optional<T>::value

      From cppreference.com
      <cpp‎ |experimental‎ |optional
       
       
       
       
       
      constexpr T& value()&;
      constexprconst T& value()const&;
      (1)(library fundamentals TS)
      constexpr T&& value()&&;
      constexprconst T&& value()const&&;
      (2)(library fundamentals TS)

      Returns the contained value.

      1) Equivalent toreturnbool(*this)?*val:throw bad_optional_access();.
      2) Equivalent toreturnbool(*this)? std::move(*val):throw bad_optional_access();.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      A reference to the contained value.

      [edit]Exceptions

      std::experimental::bad_optional_access if*this does not contain a value.

      [edit]Notes

      The dereference operatoroperator*() does not check if this optional contains a value, which may be more efficient thanvalue().

      [edit]Example

      Run this code
      #include <experimental/optional>#include <iostream> int main(){std::experimental::optional<int> opt={}; try{int n= opt.value();}catch(conststd::logic_error& e){std::cout<< e.what()<<'\n';}}

      Possible output:

      optional<T>::value: not engaged

      [edit]See also

      returns the contained value if available, another value otherwise
      (public member function)[edit]
      accesses the contained value
      (public member function)[edit]
      (library fundamentals TS)
      exception indicating checked access to an optional that doesn't contain a value
      (class)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/optional/value&oldid=155044"

      [8]ページ先頭

      ©2009-2025 Movatter.jp