小编ecl*_*pse的帖子

为什么boost :: asio :: io_service不能用std :: bind编译?

我正在尝试编译简单的测试程序std::thread,std::bindboost::asio使用g++4.9.1(-std=c++11).

但是,在创建新线程时,它在我使用时不会编译std::bind.另一方面,当我切换到boost::bind一切都很好.

这是代码:

#include <iostream>
#include <memory>
#include <thread>
#include <functional>
#include <boost/asio.hpp>
#include <boost/bind.hpp>

int main(int argc, char* argv[])
{
    boost::asio::io_service ioService;
    std::unique_ptr<std::thread> t;

    t.reset(new std::thread(std::bind(&boost::asio::io_service::run, &ioService)));
    //t.reset(new std::thread(boost::bind(&boost::asio::io_service::run, &ioService)));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

test.cpp: In function ‘int main(int, char**)’:
test.cpp:12:80: error: no matching function for call to ‘bind(<unresolved overloaded function type>, boost::asio::io_service*)’
    t.reset(new std::thread(std::bind(&boost::asio::io_service::run, &ioService)));
                                                                                            ^
test.cpp:12:80: note: candidates are:
In file included from …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-asio c++11

11
推荐指数
2
解决办法
2909
查看次数

如何为 clang 格式的外部标题创建类别?

我想配置 clang-format 以在 C++ 中对包含的标头进行排序,如下所示:

  • 主标头(与当前 cpp 文件关联),
  • 通过“”包含本地标头,
  • 通过 <> 包含的其他标头,
  • 来自特定外部库的头文件(例如 boost、catch2),
  • 系统/标准标头。

我在 macOS 上使用 clang-format 8.0.0。我当前的配置(仅与包含相关的片段)如下:

SortIncludes: true
IncludeBlocks: Regroup
IncludeCategories:
  # Headers in <> without extension.
  - Regex:           '<([A-Za-z0-9\/-_])+>'
    Priority:        4
  # Headers in <> from specific external libraries.
  - Regex:           '<((\bboost\b)|(\bcatch2\b))\/([A-Za-z0-9.\/-_])+>'
    Priority:        3
  # Headers in <> with extension.
  - Regex:           '<([A-Za-z0-9.\/-_])+>'
    Priority:        2
  # Headers in "" with extension.
  - Regex:           '"([A-Za-z0-9.\/-_])+"'
    Priority:        1
Run Code Online (Sandbox Code Playgroud)

在此配置中,我假设系统/标准标头没有扩展名。它不适用于 UNIX/POSIX 标头。主标头会自动检测并分配优先级 0。到目前为止,除了外部库的类别之外,一切似乎都按预期工作。看起来 clang-format 正在将其分配给优先级 2。

预期结果:

#include …
Run Code Online (Sandbox Code Playgroud)

c++ regex clang llvm-clang clang-format

11
推荐指数
2
解决办法
4031
查看次数

如何在 C++ 服务器应用程序和 django Web 应用程序之间进行通信

我有一些框架在 C++ 和一个基于 django 的 Web 应用程序中执行特定任务。这个想法是启动这个框架,从中接收一些数据,发送一些数据或请求并检查它在某个时期的状态。

我正在寻找最好的沟通方式。两个应用程序都运行在同一台服务器上。我想知道 C++ 中的 json 服务器是否是个好主意。Django 会向这个服务器发送一个请求,服务器会解析它,并委托一个工作线程来完成任务。几乎所有需要发送的数据都是类似字符串的。其他数据将存储在数据库中,因此没有问题。

JSON 是个好主意吗?也许你知道一些更好的 C++ 和 django 之间本地通信的机制?

c++ python django json

4
推荐指数
2
解决办法
6245
查看次数

标签 统计

c++ ×3

boost ×1

boost-asio ×1

c++11 ×1

clang ×1

clang-format ×1

django ×1

json ×1

llvm-clang ×1

python ×1

regex ×1