Standard library header <future> (C++11)
From cppreference.net
此头文件是 线程支持 库的组成部分。
类 |
||
|
(C++11)
|
存储用于异步获取的值
(类模板) |
|
|
(C++11)
|
包装函数以存储其返回值供异步获取
(类模板) |
|
|
(C++11)
|
等待异步设置的值
(类模板) |
|
|
(C++11)
|
等待异步设置的值(可能被其他 future 引用)
(类模板) |
|
|
(C++11)
|
指定
std::async
的启动策略
(枚举) |
|
|
(C++11)
|
指定在
std::future
和
std::shared_future
上执行的定时等待结果
(枚举) |
|
|
(C++11)
|
报告与 future 或 promise 相关的错误
(类) |
|
|
(C++11)
|
标识 future 错误码
(枚举) |
|
|
特化
std::uses_allocator
类型特征
(类模板特化) |
||
|
(C++11)
(until C++17)
|
特化
std::uses_allocator
类型特征
(类模板特化) |
|
函数 |
||
|
(C++11)
|
异步运行函数(可能在新线程中)并返回将保存结果的
std::future
(函数模板) |
|
|
(C++11)
|
标识 future 错误类别
(函数) |
|
|
(C++11)
|
特化
std::swap
算法
(函数模板) |
|
|
(C++11)
|
特化
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; }; }
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; }