future
2024-08-27 06:48:24
/*T ->return type, E -> error type, D -> parameter type */
template<typename T, typename E, typename D = void>
using result_t = typename internal::result_t<T, E, D>::type;
第一个参数类型T是返回的Result<1, 2>中参数1,第二个参数类型参数E为参数2,参数D为函数参数的类型.
template<typename T>
struct State
{
std::mutex mutex;
std::experimental::optional<T> value;
std::unique_ptr<detail::ContinuationBase<T&>> continuation; // 注意这里并不是一个引用类型, 而是一个 ContinuationBase<int&> class类似, ContinuationBase是不用做引用类型的初始化.
}
template<typename T>
class Promise
{
.....
private:
std::shared_ptr<typename detail::State<T>> _state;
};
template<typename T>
class Future
{
private:
std::shared_ptr<detail::State<T>> _state;
friend class Promise<T>;
};
Promise 和 Future 通过 std::shared_ptr<detail::State<T>> _state;连接.
template<typename... Args>
class ContinuationBase
{
public:
virtual ~ContinuationBase() {}
virtual void operator () (Args&&... args) = 0;
};
template<typename F, typename... Args>
class Continuation : public ContinuationBase<Args...>
{
static_assert(!std::is_reference<F> {}, "F cannot be a reference");
public:
typedef result_of<F, Args...> result_type;
Continuation(const F& fun) : _fun(fun)
{
}
Continuation(F&& fun) : _fun(std::move(fun))
{
}
}
最新文章
- 【bzoj3211】花神游历各国
- Unity 热更新实例一、C#Light 和UI系统使用实例
- 如何解决Android SDK中离线文档打开慢的问题
- Windows-005-显示隐藏文件
- 网络攻击之二:XSS(之一是SQL注入,前面有文章)
- mybatis 打印 sql
- 加密算法 - RSA算法二
- Linux 系统下查看硬件信息命令大全
- 再淡spring jdbc 连接池断开重连设置
- muduo网络图书馆评测
- php实现分页
- 用u盘装系统,进入bios后没有usb启动项怎么办
- MySQL简概
- 一 Django模型层简介(一)
- Java并发-对象共享
- 章节十、3-CSS Selector---用CSS Selector - ID定位元素
- vue获取路由地址栏url里面的指定参数
- npm ERR! Cannot read property &#39;path&#39; of null
- ls -l 和du 的区别
- 4.ClassLink - 一种新型的VPC 经典网络的连接方式