Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::when_any

      From cppreference.com
      <cpp‎ |experimental
       
       
       
       
      Defined in header<experimental/future>
      template<class Sequence>

      struct when_any_result{
         std::size_t index;
          Sequence futures;

      };
      (concurrency TS)
      template<class InputIt>

      auto when_any( InputIt first, InputIt last)

         -> future<when_any_result<std::vector<typenamestd::iterator_traits<InputIt>::value_type>>>;
      (1)(concurrency TS)
      template<class...Futures>

      auto when_any( Futures&&...futures)

         -> future<when_any_result<std::tuple<std::decay_t<Futures>...>>>;
      (2)(concurrency TS)

      Create afuture object that becomes ready when at least one of the inputfutures andshared_futures become ready. The behavior is undefined if any inputfuture orshared_future is invalid.

      In particular, letSequence be astd::vector<typenamestd::iterator_traits<InputIt>::value_type> for(1) andstd::tuple<std::decay_t<Futures>...> for(2). This function template creates a shared state containingwhen_any_result<Sequence> and returns a future referring to the shared state. Every inputfuture is moved into the corresponding object in thefutures member of thewhen_any_result<Sequence> in the shared state, and every inputshared_future is copied to the corresponding object in thefutures member of thewhen_any_result<Sequence> in the shared state. The order of the objects in theSequence matches the order of arguments.

      1) This function does not participate in overload resolution unlessInputIt's value type (i.e.,typenamestd::iterator_traits<InputIt>::value_type) is astd::experimental::future orstd::experimental::shared_future.
      2) This function does not participate in overload resolution unless every argument is either a (possibly cv-qualified)std::experimental::shared_future or a cv-unqualifiedstd::experimental::future. (Formally, for every typeFn inFutures, eitherstd::remove_reference_t<Fn> isstd::experimental::future<Rn>, orstd::decay_t<Fn> isstd::experimental::shared_future<Rn>.)

      After this call, every inputfuture is no longer valid; every inputshared_future remains valid.

      [edit]Return value

      Afuture referring to the shared state created by the call. The future is alwaysvalid(), and it becomes ready when at least one of the inputfutures andshared_futures the call are ready. Theindex member of thewhen_any_result contains the position of the readyfuture orshared_future in thefutures member.

      1) If the range is empty (i.e.,first== last), the returnedfuture is ready immediately; thefutures field of thewhen_any_result is an empty vector, and theindex field issize_t(-1).
      2) If no argument is provided, the returnedfuture is ready immediately; thefutures field of thewhen_any_result is an empty tuple, and theindex field issize_t(-1).
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/when_any&oldid=156385"

      [8]ページ先頭

      ©2009-2025 Movatter.jp