Namespaces
Variants

Standard library header <future> (C++11)

From cppreference.net
Standard library headers

このヘッダは スレッドサポート ライブラリの一部です。

目次

クラス

(C++11)
非同期取得のための値を格納する
(クラステンプレート)
非同期取得のために戻り値を格納する関数をパッケージ化する
(クラステンプレート)
(C++11)
非同期に設定される値を待機する
(クラステンプレート)
非同期に設定される値(他のfutureによって参照される可能性がある)を待機する
(クラステンプレート)
(C++11)
std::async の起動ポリシーを指定する
(列挙型)
std::future および std::shared_future で実行されるタイムドウェイトの結果を指定する
(列挙型)
futureまたはpromiseに関連するエラーを報告する
(クラス)
フューチャーエラーコードを識別する
(列挙型)
std::uses_allocator 型特性を特殊化
(クラステンプレートの特殊化)
std::uses_allocator型特性を特殊化
(クラステンプレートの特殊化)

関数

(C++11)
関数を非同期で(場合によっては新しいスレッドで)実行し、結果を保持する std::future を返す
(関数テンプレート)
futureエラーカテゴリを識別する
(関数)
std::swap アルゴリズムを特殊化
(関数テンプレート)
std::swap アルゴリズムを特殊化
(関数テンプレート)

概要

namespace std {
  enum class future_errc {
    broken_promise = /* 実装定義 */,
    future_already_retrieved = /* 実装定義 */,
    promise_already_satisfied = /* 実装定義 */,
    no_state = /* 実装定義 */
  };
  enum class launch : /* 未指定 */ {
    async = /* 未指定 */,
    deferred = /* 未指定 */,
    /* 実装定義 */
  };
  enum class future_status {
    ready,
    timeout,
    deferred
  };
  template<> struct is_error_code_enum<future_errc> : public true_type { };
  error_code make_error_code(future_errc e) noexcept;
  error_condition make_error_condition(future_errc e) noexcept;
  const error_category& future_category() noexcept;
  class future_error;
  template<class R> class promise;
  template<class R> class promise<R&>;
  template<> class promise<void>;
  template<class R>
    void swap(promise<R>& x, promise<R>& y) noexcept;
  template<class R, class Alloc>
    struct uses_allocator<promise<R>, Alloc>;
  template<class R> class future;
  template<class R> class future<R&>;
  template<> class future<void>;
  template<class R> class shared_future;
  template<class R> class shared_future<R&>;
  template<> class shared_future<void>;
  template<class> class packaged_task;  // 未定義
  template<class R, class... ArgTypes>
    class packaged_task<R(ArgTypes...)>;
  template<class R, class... ArgTypes>
    void swap(packaged_task<R(ArgTypes...)>&, packaged_task<R(ArgTypes...)>&) noexcept;
  template<class F, class... Args>
    future<invoke_result_t<decay_t<F>, decay_t<Args>...>>
      async(F&& f, Args&&... args);
  template<class F, class... Args>
    future<invoke_result_t<decay_t<F>, decay_t<Args>...>>
      async(launch policy, F&& f, Args&&... args);
}

クラス std::future_error

namespace std {
  class future_error : public logic_error {
  public:
    explicit future_error(future_errc e);
    const error_code& code() const noexcept;
    const char*       what() const noexcept;
  private:
    error_code ec_;             // 説明専用
  };
}

クラステンプレート std::promise

namespace std {
  template<class R>
  class promise {
  public:
    promise();
    template<class Allocator>
      promise(allocator_arg_t, const Allocator& a);
    promise(promise&& rhs) noexcept;
    promise(const promise&) = delete;
    ~promise();
    // 代入
    promise& operator=(promise&& rhs) noexcept;
    promise& operator=(const promise&) = delete;
    void swap(promise& other) noexcept;
    // 結果の取得
    future<R> get_future();
    // 結果の設定
    void set_value(/* 詳細は説明を参照 */);
    void set_exception(exception_ptr p);
    // 遅延通知による結果の設定
    void set_value_at_thread_exit(/* 詳細は説明を参照 */);
    void set_exception_at_thread_exit(exception_ptr p);
  };
  template<class R>
    void swap(promise<R>& x, promise<R>& y) noexcept;
  template<class R, class Alloc>
    struct uses_allocator<promise<R>, Alloc>;
}

クラステンプレート std::future

namespace std {
  template<class R>
  class future {
  public:
    future() noexcept;
    future(future&&) noexcept;
    future(const future&) = delete;
    ~future();
    future& operator=(const future&) = delete;
    future& operator=(future&&) noexcept;
    shared_future<R> share() noexcept;
    // 値の取得
    /* 説明を参照 */ get();
    // 状態確認関数
    bool valid() const noexcept;
    void wait() const;
    template<class Rep, class Period>
      future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
    template<class Clock, class Duration>
      future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
  };
}

クラステンプレート std::shared_future

namespace std {
  template<class R>
  class shared_future {
  public:
    shared_future() noexcept;
    shared_future(const shared_future& rhs) noexcept;
    shared_future(future<R>&&) noexcept;
    shared_future(shared_future&& rhs) noexcept;
    ~shared_future();
    shared_future& operator=(const shared_future& rhs) noexcept;
    shared_future& operator=(shared_future&& rhs) noexcept;
    // 値の取得
    /* 説明を参照 */ get() const;
    // 状態確認関数
    bool valid() const noexcept;
    void wait() const;
    template<class Rep, class Period>
      future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
    template<class Clock, class Duration>
      future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
  };
}

クラステンプレート std::packaged_task

namespace std {
  template<class> class packaged_task;  // 未定義
  template<class R, class... ArgTypes>
  class packaged_task<R(ArgTypes...)> {
  public:
    // 構築と破棄
    packaged_task() noexcept;
    template<class F>
      explicit packaged_task(F&& f);
    ~packaged_task();
    // コピー不可
    packaged_task(const packaged_task&) = delete;
    packaged_task& operator=(const packaged_task&) = delete;
    // ムーブサポート
    packaged_task(packaged_task&& rhs) noexcept;
    packaged_task& operator=(packaged_task&& rhs) noexcept;
    void swap(packaged_task& other) noexcept;
    bool valid() const noexcept;
    // 結果取得
    future<R> get_future();
    // 実行
    void operator()(ArgTypes... );
    void make_ready_at_thread_exit(ArgTypes...);
    void reset();
  };
  template<class R, class... ArgTypes>
  packaged_task(R (*)(ArgTypes...)) -> packaged_task<R(ArgTypes...)>;
  template<class F> packaged_task(F) -> packaged_task</* 説明を参照 */>;
  template<class R, class... ArgTypes>
    void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
}