小编Hwa*_*n E的帖子

epoll 和 boost::asio::io_context 有什么区别?

我知道 epoll 和 io_context 异步工作。那么,您能告诉我两者有什么区别吗?

你在 asio::io_context 中使用 epoll 吗?

c++ epoll boost-asio

4
推荐指数
1
解决办法
1869
查看次数

“ vector <int> v []”和“ vector <vector <int >> v”之间有什么区别?

我不知道之间的区别vector<int> v[]vector<vector<int>> v

vector<int>v[] = {{ 0, 1 }, { 2, 3 }};

v[0][0] = 4;
v[0][1] = 2;
v[0].push_back(4);

for (int i = 0; i < v[0].size(); i++)
    cout << v[0][i] << endl;

cout << v[1][0] << endl;
Run Code Online (Sandbox Code Playgroud)

输出:4 2 4 2

vector<vector<int>> v = { {0, 1}, {2, 3} };

v[0][0] = 4;
v[0][1] = 2;
v[0].push_back(4);

for (int i = 0; i < v[0].size(); i++)
    cout << v[0][i] << endl;

cout << v[1][0] << …
Run Code Online (Sandbox Code Playgroud)

c++ vector

3
推荐指数
1
解决办法
50
查看次数

C ++ lambda的机制是什么?

我正在学习lambda。

但是我有一个问题。

#include <iostream>

using namespace std;

int main() {
    int x = 10;

    auto l1 = [&](){
        x = 5;
        return x;
    };

    auto l2 = [&, x = x + 100](){
        return x;   
    };

    cout << l1() << endl;
    cout << "main  x  : " << x << endl;;
    cout << l2() << endl;
    cout << "main  x  : " << x << endl;;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

此代码的输出是:

5
main x : 5
110
main x : 5 …
Run Code Online (Sandbox Code Playgroud)

c++ lambda scope initialization reference

1
推荐指数
1
解决办法
129
查看次数

C++ 我不知道在使用回调函数时使用“this”和“std::placeholders::_1”是什么意思

我正在尝试通过查看 cpprestSDK 的示例代码来制作服务器。但是我不知道为什么我在示例代码中绑定。

下面是示例代码。

标准文件文件

class Handler{
public:
    Handler() {};
    Handler(utility::string_t url);

    pplx::task<void> open() { return m_listener.open(); }
    pplx::task<void> close() { return m_listener.close(); }

private:
    void handle_get(http_request request);
    void handle_put(http_request request);
    void handle_post(http_request request);
    void handle_del(http_request request);
};
Run Code Online (Sandbox Code Playgroud)

处理程序

  
#include "stdafx.hpp"

Handler::Handler(utility::string_t url) : m_listener(url)
{

    m_listener.support(methods::GET, std::bind(&Handler::handle_get, this, std::placeholders::_1));
    m_listener.support(methods::PUT, std::bind(&Handler::handle_put, this, std::placeholders::_1));
    m_listener.support(methods::POST, std::bind(&Handler::handle_post, this, std::placeholders::_1));
    m_listener.support(methods::DEL, std::bind(&Handler::handle_del, this, std::placeholders::_1));
}
Run Code Online (Sandbox Code Playgroud)

查看支持的参考,它的定义如下。

void support (const http::method &method, const std::function< void(http_request)> &handler)

我以为我可以这样定义它:

m_listener.support(methods::GET, &Handler::handle_get);

但它失败了。

你能告诉我为什么我在绑定时使用“this”和“std::placeholders::_1”吗?

示例代码:https …

c++ stdbind cpprest-sdk

1
推荐指数
1
解决办法
145
查看次数

Go 的堆栈是拆分还是堆栈复制?

我对 Go 的堆栈管理感兴趣。我搜索了各种数据,但它让我感到困惑,因为所有数据都不同。我比较好奇的是,golang 的栈管理是栈拆分还是栈复制。

正确答案是什么?

golang 版本:go1.16.3

stack go

1
推荐指数
1
解决办法
74
查看次数