Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |utility‎ |expected
       
       
      Utilities library
       
       
      Main template
      constexpr expected();
      (1)(since C++23)
      constexpr expected(const expected& other);
      (2)(since C++23)
      constexpr expected( expected&& other)noexcept(/* see below */);
      (3)(since C++23)
      template<class U,class G>
      constexpr expected(const expected<U, G>& other);
      (4)(since C++23)
      (conditionally explicit)
      template<class U,class G>
      constexpr expected( expected<U, G>&& other);
      (5)(since C++23)
      (conditionally explicit)
      template<class U=std::remove_cv_t<T>>
      constexprexplicit(!std::is_convertible_v<U, T>) expected( U&& v);
      (6)(since C++23)
      template<class G>

      constexprexplicit(!std::is_convertible_v<const G&, E>)

          expected(conststd::unexpected<G>& e);
      (7)(since C++23)
      template<class G>

      constexprexplicit(!std::is_convertible_v<G, E>)

          expected(std::unexpected<G>&& e);
      (8)(since C++23)
      template<class...Args>
      constexprexplicit expected(std::in_place_t, Args&&...args);
      (9)(since C++23)
      template<class U,class...Args>

      constexprexplicit
          expected(std::in_place_t,

                   std::initializer_list<U> il, Args&&...args);
      (10)(since C++23)
      template<class...Args>
      constexprexplicit expected(std::unexpect_t, Args&&...args);
      (11)(since C++23)
      template<class U,class...Args>

      constexprexplicit
          expected(std::unexpect_t,

                   std::initializer_list<U> il, Args&&...args);
      (12)(since C++23)
      void partial specialization
      constexpr expected();
      (13)(since C++23)
      constexpr expected(const expected& other);
      (14)(since C++23)
      constexpr expected( expected&& other)
         noexcept(std::is_nothrow_move_constructible_v<E>);
      (15)(since C++23)
      template<class U,class G>

      constexprexplicit(!std::is_convertible_v<const G&, E>)

          expected(const expected<U, G>& other);
      (16)(since C++23)
      template<class U,class G>

      constexprexplicit(!std::is_convertible_v<G, E>)

          expected( expected<U, G>&& other);
      (17)(since C++23)
      template<class G>

      constexprexplicit(!std::is_convertible_v<const G&, E>)

          expected(conststd::unexpected<G>& e);
      (18)(since C++23)
      template<class G>

      constexprexplicit(!std::is_convertible_v<G, E>)

          expected(std::unexpected<G>&& e);
      (19)(since C++23)
      constexprexplicit expected(std::in_place_t);
      (20)(since C++23)
      template<class...Args>
      constexprexplicit expected(std::unexpect_t, Args&&...args);
      (21)(since C++23)
      template<class U,class...Args>

      constexprexplicit
          expected(std::unexpect_t,

                   std::initializer_list<U> il, Args&&...args);
      (22)(since C++23)

      Constructs a newexpected object.

      Contents

      [edit]Parameters

      other - anotherexpected object whose contained value is copied
      e -std::unexpected object whose contained value is copied
      v - value with which to initialize the contained value
      args - arguments with which to initialize the contained value
      il - initializer list with which to initialize the contained value

      [edit]Effects

      [edit]Primary template constructors

      OverloadInitialization
      method
      Initializer for...has_value()
      after construction
      the expected valuethe unexpected value
      (1)Value(empty)-true
      (2)Direct
      (non-list)
      *otherother.error()other.has_value()
      • Iftrue, only initializes the expected value.
      • Iffalse, only initializes the unexpected value.
      (3)std::move(*other)std::move(other.error())
      (4)std::forward<const U&>
         (*other)
      std::forward<const G&>
         (other.error())
      (5)std::forward<U>(*other)std::forward<G>
         (other.error())
      (6)std::forward<U>(v)-true
      (7)-std::forward<const G&>
         (e.error())
      false
      (8)std::forward<G>(e.error())
      (9)std::forward<Args>(args)...-true
      (10)il,
      std::forward<Args>(args)...
      (11)-std::forward<Args>(args)...false
      (12)il,
      std::forward<Args>(args)...

      [edit]void partial specialization constructors

      OverloadInitialization methodInitializer for the unexpected valuehas_value() after construction
      (13)N/A-true
      (14)Direct (non-list)rhs.error()other.has_value()
      • Iffalse, initializes the unexpected value.
      (15)std::move(rhs.error)
      (16)std::forward<const G&>(rhs.error())
      (17)std::forward<G>(rhs.error())
      (18)std::forward<const G&>(e.error())false
      (19)std::forward<G>(e.error())
      (20)N/A-true
      (21)Direct (non-list)std::forward<Args>(args)...false
      (22)il,std::forward<Args>(args)...

      [edit]Constraints and supplement information

      [edit]Primary template constructors

      1) This overload participates in overload resolution only ifstd::is_default_constructible_v<T> istrue.
      2) This constructor is defined as deleted unlessstd::is_copy_constructible_v<T> andstd::is_copy_constructible_v<E> are bothtrue.
      This constructor is trivial ifstd::is_trivially_copy_constructible_v<T> andstd::is_trivially_copy_constructible_v<E> are bothtrue.
      3) This overload participates in overload resolution only ifstd::is_move_constructible_v<T> andstd::is_move_constructible_v<E> are bothtrue.
      This constructor is trivial ifstd::is_trivially_move_constructible_v<T> andstd::is_trivially_move_constructible_v<E> are bothtrue.
      4,5) These overloads participate in overload resolution only if all following conditions are satisfied:
      4) This constructor isexplicit ifstd::is_convertible_v<const U&, T> orstd::is_convertible_v<const G&, E> isfalse.
      5) This constructor isexplicit ifstd::is_convertible_v<U, T> orstd::is_convertible_v<G, E> isfalse.
      6) This overload participates in overload resolution only if all following conditions are satisfied:
      7) This overload participates in overload resolution only ifstd::is_constructible_v<E,const G&> istrue.
      8) This overload participates in overload resolution only ifstd::is_constructible_v<E, G> istrue.
      9) This overload participates in overload resolution only ifstd::is_constructible_v<T, Args...> istrue.
      10) This overload participates in overload resolution only ifstd::is_constructible_v<T,std::initializer_list<U>&, Args...> istrue.
      11) This overload participates in overload resolution only ifstd::is_constructible_v<E, Args...> istrue.
      12) This overload participates in overload resolution only ifstd::is_constructible_v<E,std::initializer_list<U>&, Args...> istrue.

      [edit]void partial specialization constructors

      14) This constructor is defined as deleted unlessstd::is_copy_constructible_v<E> istrue.
      This constructor is trivial ifstd::is_trivially_copy_constructible_v<E> istrue.
      15) This overload participates in overload resolution only ifstd::is_move_constructible_v<E> istrue.
      This constructor is trivial ifstd::is_trivially_move_constructible_v<E> istrue.
      16,17) These overloads participate in overload resolution only if all following conditions are satisfied:
      18) This overload participates in overload resolution only ifstd::is_constructible_v<E,const G&> istrue.
      19) This overload participates in overload resolution only ifstd::is_constructible_v<E, G> istrue.
      21) This overload participates in overload resolution only ifstd::is_constructible_v<E, Args...> istrue.
      22) This overload participates in overload resolution only ifstd::is_constructible_v<E,std::initializer_list<U>&, Args...> istrue.

      [edit]Exceptions

      [edit]Primary template constructors

      1) Throws any exception thrown by the initialization of the expected value.
      2) Throws any exception thrown by the initialization of the expected or unexpected value.
      3) Throws any exception thrown by the initialization of the expected or unexpected value.
      4,5) Throws any exception thrown by the initialization of the expected or unexpected value.
      6) Throws any exception thrown by the initialization of the expected value.
      7,8) Throws any exception thrown by the initialization of the unexpected value.
      9,10) Throws any exception thrown by the initialization of the expected value.
      11,12) Throws any exception thrown by the initialization of the unexpected value.

      [edit]void partial specialization constructors

      14-19) Throws any exception thrown by the initialization of the unexpected value.
      21,22) Throws any exception thrown by the initialization of the 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 3886C++23the default template argument of overload(6) wasTchanged tostd::remove_cv_t<T>

      [edit]See also

      (C++23)
      represented as an unexpected value
      (class template)[edit]
      in-place construction tag
      (tag)[edit]
      in-place construction tag for unexpected value inexpected
      (tag)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/expected/expected&oldid=182928"

      [8]ページ先頭

      ©2009-2025 Movatter.jp