• C++17 新特性


    boost::asio

    可用于如socket等IO对象的同步或异步操作,

    应用程序必须有一个io_service对象. io_service对象负责连接应用程序与操作系统的IO服务.

    boost::asio::io_service io_service;

    要执行IO操作应用程序需要一个像TCP Socket的IO对象:

    boost::asio::ip::tcp::socket socket(io_service);

    而后执行同步连接操作,发送如下事件:

    1. 应用程序调用IO对象的初始化连接操作:

    socket.connect(server_endpoint);

    2. IO对象向io_service 提出请求.

    3. io_service 调用操作系统的功能执行连接操作.

    4. 操作系统向io_service 返回执行结果.

    5. io_service将错误的操作结果翻译为boost::system::error_code类型. error_code可与特定值进行比较,或作为boolean值检测(false表示无错误).结果再传递给IO对象.

    6. 如果操作失败,IO对象抛出boost::system::system_error类型的异常.

    参考链接

    http://www.boost.org/doc/libs/1_64_0/doc/html/boost_asio.html

    http://blog.csdn.net/henreash/article/details/7469707  

    Coroutines

    lua的一段代码

    function foo(a)
        print("foo", a)
        return coroutine.yield(2 * a)
    end
    
    co = coroutine.create(function ( a, b )
        print("co-body", a, b)
        local r = foo(a + 1)
        print("co-body", r)
        local r, s = coroutine.yield(a + b, a - b)
        print("co-body", r, s)
        return b, "end"
    end)
    
    print("main", coroutine.resume(co, 1, 10))
    print("main", coroutine.resume(co, "r"))
    print("main", coroutine.resume(co, "x", "y"))
    print("main", coroutine.resume(co, "x", "y"))
    
    下面是运行结果
    
    co-body 1 10  //print("co-body", a, b)
    
    foo 2  //print("foo", a)
    
    main true 4 //print("main", coroutine.resume(co, 1, 10)),resume第一值返回true,第二个值返回上次yield(coroutine.yield(2 * a))的入参 4
    
    co-body r // print("co-body", r) r为上一次yield的返回值,即这一次resume的入参 "r"
    
    main true 11, -9 //print("main", coroutine.resume(co, "r")),resume第一值返回true,第二个值返回上次yield( local r, s = coroutine.yield(a + b, a - b))的入参 11, -9
    
    co-body x y // print("co-body", r, s) r,s为上一次yield的返回值,即这一次resume的入参 "x",y"
    
    main true 10 end  //print("main", coroutine.resume(co, "x", "y")), resume第一值返回true,第二个值返回create的返回值b, "end"
    
    main false cannot resume dead coroutine //coroutine已经完成

    std::apply

    template <class F, class Tuple>
    constexpr decltype(auto) apply(F&& f, Tuple&& t);

    //f是函数,t是一串入参

    #include <iostream>
    #include <tuple>
    #include <utility>
     
    int add(int first, int second) { return first + second; }
     
    template<typename T>
    T add_generic(T first, T second) { return first + second; }
     
    auto add_lambda = [](auto first, auto second) { return first + second; };
     
    int main()
    {
        // OK
        std::cout << std::apply(add, std::make_pair(1, 2)) << '
    ';
     
       // Error: can't deduce the function type
       // std::cout << std::apply(add_generic, std::make_pair(2.0f, 3.0f)) << '
    '; 
     
       // OK
       std::cout << std::apply(add_lambda, std::make_pair(2.0f, 3.0f)) << '
    '; 
    }
    
    //3
    //5

    参考链接 http://en.cppreference.com/w/cpp/utility/apply

  • 相关阅读:
    LCS(最长公共子序列)
    如何利用MAXScript代码进行DNA双螺旋结构的创建
    如何在3ds MAX中进行宏脚本MacroScript的编写
    3dsmax:[5]maxscript是干什么的
    Visual MAXScript 工具
    3D MAXScript(1)
    如何写3DMAX的插件
    利用GitHub for Window 来进行项目的上传
    VS中的库
    软件测试作业
  • 原文地址:https://www.cnblogs.com/zengyou/p/7770697.html
Copyright © 2020-2023  润新知