/*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))
    {
    }
}

future的更多相关文章

  1. 面向未来的友好设计:Future Friendly

    一年前翻译了本文的一部分,最近终于翻译完成.虽然此设计思想的提出已经好几年了,但是还是觉得应该在国内推广一下,让大家知道“内容策略”,“移动优先”,“响应式设计”,“原子设计”等设计思想和技术的根源. ...

  2. 线程笔记:Future模式

    线程技术可以让我们的程序同时做多件事情,线程的工作模式有很多,常见的一种模式就是处理网站的并发,今天我来说说线程另一种很常见的模式,这个模式和前端里的ajax类似:浏览器一个主线程执行javascri ...

  3. 第二篇 Entity Framework Plus 之 Query Future

    从性能的角度出发,能够减少 增,删,改,查,跟数据库打交道次数,肯定是对性能会有所提升的(这里单纯是数据库部分). 今天主要怎样减少Entity Framework查询跟数据库打交道的次数,来提高查询 ...

  4. Eclipse调试Android App若选择“Use same device for future launches”就再也无法选择其他设备的问题

    在狂批了某供应商的多媒体控制App有多烂后,夸下海口自己要做一个也是分分钟的事.当然要做好不容易,要超过他们的烂软件还是有信心的.过程中遇到各种坑,其中之一如下 刚开始只使用一个平板进行调试,老是弹出 ...

  5. java Future 接口介绍

    (转自:http://blog.csdn.net/yangyan19870319/article/details/6093481) 在Java中,如果需要设定代码执行的最长时间,即超时,可以用Java ...

  6. java多线程系类:JUC线程池:06之Callable和Future(转)

    概要 本章介绍线程池中的Callable和Future.Callable 和 Future 简介示例和源码分析(基于JDK1.7.0_40) 转载请注明出处:http://www.cnblogs.co ...

  7. 架构师养成记--9.future模式讲解

    什么是future模式呢?解释这个概念之前我们先来了解一个场景吧,财务系统的结账功能,这个功能可能是每个月用一次,在这一个月中相关的数据量已经积累得非常大,这一个功能需要调用好几个存储过程来完成.假如 ...

  8. Future和Promise

    Future用于获取异步操作的结果,而Promise则比较抽象,无法直接猜测出其功能. Future Future最早来源于JDK的java.util.concurrent.Future,它用于代表异 ...

  9. Java--Callable与返回值future

    package com; import java.util.concurrent.*; /** * Created by yangyu on 16/11/28. */ /** * Callable a ...

  10. Java多线程系列--“JUC线程池”06之 Callable和Future

    概要 本章介绍线程池中的Callable和Future.Callable 和 Future 简介示例和源码分析(基于JDK1.7.0_40) 转载请注明出处:http://www.cnblogs.co ...

随机推荐

  1. Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth Key

    Send Push Notifications to iOS Devices using Xcode 8 and Swift 3 OCT 6, 2016 Push notifications are ...

  2. 通过git在github上建立gh-pages分支并查看网页效果

    建立gh-pages分支:    进入到你想要上传的文件夹下:           cd text(text为文件夹名)           git初始化           git init   创 ...

  3. Android SDK ADT下载地址

    http://dl.google.com/android/android-sdk_rXX-windows.zip http://dl.google.com/android/ADT-X.X.X.zip ...

  4. java.lang.ClassCastException: org.slf4j.impl.Log4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext问题原因及解决方法

    一.错误信息 java.lang.ClassCastException: org.slf4j.impl.Log4jLoggerFactory cannot be cast to ch.qos.logb ...

  5. OGRE的学习资源

    本文介绍从哪儿开始学习OGRE(Object-Oriented Graphics Rendering Engine的简称,又叫做OGRE 3D),如何在网上找寻OGRE的学习资源. 首先是wikipe ...

  6. c数据结构 顺序表和链表 相关操作

    编译器:vs2013 内容: #include "stdafx.h"#include<stdio.h>#include<malloc.h>#include& ...

  7. HTML5获取地理位置

    包含了以下功能:(1)通过IP地址获取城市地址(并不完全准确,存在代理IP或IP中转时定位与实际位置不一致的情况)(2)通过移动端浏览器及GPS定位位置坐标(3)根据位置坐标转换百度地图坐标(4)根据 ...

  8. Xcode开发openCV for iOS 时#include <list> not found

    分析 在做混合编译之前一定要把编译器的Compile Sources As选项改为Objective C++. 默认的选项是According to file type,用这个的话,你后面每个不在交叉 ...

  9. .NET 框架(转自wiki)

    .NET Framework (pronounced dot net) is a software framework developed by Microsoft that runs primari ...

  10. 成员资格、授权 – ASP.NET MVC 4 系列

           ASP.NET MVC 不像 ASP.NET WEB FORMS 那样提供了很多自动保护机制来保护页面不受恶意用户的攻击,更明确的说,后者是致力于使应用程序免受攻击: 服务器组件对显示的 ...