Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::expected<T,E>::value

      From cppreference.com
      <cpp‎ |utility‎ |expected
       
       
      Utilities library
       
       
      Primary template
      constexpr T& value()&;
      (1)(since C++23)
      constexprconst T& value()const&;
      (2)(since C++23)
      constexpr T&& value()&&;
      (3)(since C++23)
      constexprconst T&& value()const&&;
      (4)(since C++23)
      void partial specialization
      constexprvoid value()const&;
      (5)(since C++23)
      constexprvoid value()&&;
      (6)(since C++23)

      If*this contains an expected value, returns a reference to the contained value. Returns nothing forvoid partial specialization.

      Otherwise, throws an exception of typestd::bad_expected_access<std::decay_t<E>> that contains a copy oferror().

      1,2) Ifstd::is_copy_constructible_v<E> isfalse, the program is ill-formed.
      3,4) Ifstd::is_copy_constructible_v<E> orstd::is_constructible_v<E, decltype(std::move(error()))> isfalse, the program is ill-formed.
      5) Ifstd::is_copy_constructible_v<E> isfalse, the program is ill-formed.
      6) Ifstd::is_move_constructible_v<E> isfalse, the program is ill-formed.

      Contents

      [edit]Return value

      1,2)val
      3,4)std::move(val)

      [edit]Exceptions

      1,2,5) Throwsstd::bad_expected_access(std::as_const(error())) if*this contains an unexpected value.
      3,4,6) Throwsstd::bad_expected_access(std::move(error())) if*this contains an unexpected value.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3940C++23E was not required to be copy/move-constructible for overloads(5,6)required

      [edit]See also

      returns the expected value if present, another value otherwise
      (public member function)[edit]
      accesses the expected value
      (public member function)[edit]
      returns the unexpected value
      (public member function)[edit]
      exception indicating checked access to anexpected that contains an unexpected value
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/expected/value&oldid=173317"

      [8]ページ先頭

      ©2009-2025 Movatter.jp