boost 相关问题

Boost是一系列旨在用于C ++的高质量库。 Boost是免费的,通常被认为是“第二标准库”。

CMake - 某些 boost 版本的补丁(复制)文件

Ubuntu 22.04 附带的 C++ Boost 1.74 具有与 C++20 不兼容的代码。在声明构建之前,我需要复制一个可用的备用文件。 以下是sni...

回答 1 投票 0

Boost Python C++ boost::python::list 输入 Python 参数类型与 C++ 签名不匹配

创建了一个测试函数来测试 Boost Python 是否可以将 Python 列表传递给 C++ 方法。但是,它会导致以下错误: Boost.Python.ArgumentError:boost_cpp 中的 Python 参数类型。

回答 1 投票 0

boost asio UDP 套接字收到“Netork 无法访问”错误。可以恢复吗?

我正在使用UDP套接字的boost包装器与远程服务器通信。这是该套接字的初始化流程(为了便于阅读,省略了错误处理。) std::shared_ptr 我正在使用 UDP 套接字的 boost 包装器与远程服务器进行通信。这是该套接字的初始化流程(为了便于阅读,省略了错误处理。) std::shared_ptr<boost::asio::ip::udp::socket> socket socket = std::make_shared<boost::asio::ip::udp::socket>(ioctx); socket->open(boost::asio::ip::udp::v4(), ec); boost::asio::ip::address server = boost::asio::ip::make_address( server_ip, ec); boost::asio::ip::udp::endpoint endpoint(server, port); socket->connect(endpoint); 初始化后,我从套接字读取数据,在极少数情况下,我会看到“网络无法访问”错误代码,该代码不是套接字接收系统调用的一部分。 auto bytes = socket->receive( boost::asio::buffer(packet->get_pkt(), packet->get_buffer_size()), 0, --> ec); 所以我想知道boost库是否在包装器中添加了这个错误,以及我是否可以继续使用这个套接字或者必须重新创建连接。 谢谢! 因此,network_unreachable(ENETUNREACH或9916)永远不会在Boost代码中显式引发。 如果你使用的是 Windows,它可能是从 翻译过来的 0x2742 由 ::GetLastError() 返回。我假设您使用的是 POSIX,因为您提到了系统调用。 WSAENETUNREACH_ 翻译为 error_condition 唯一明确提及该错误的地方是在 complete_iocp_connect 中,它翻译了 IOCP 特定错误。 目的地无法到达 此 ICMP 文档页面 阐明: 总结:网络不可达 指定的目标地址是否是有效的网络? 路由器的链路是否已发送网络不可达消息? 路由器中的端口是否配置了正确的地址掩码值? [...] 总结:主机无法访问 您可以放心,干预通信基础设施运行正常。 指定的目标地址是主机的正确地址吗? 主持人当前在线且活跃吗? 目标网络是否存在任何物理问题。 UDP 在概念上与 ICMP 非常相似(因为它们是同一层上的数据报协议)。我强烈建议您阅读整个链接页面,因为它为您提供了许多现实生活场景,这些场景通常会导致报告特定的错误情况。 总结 系统调用将返回 ENETUNREACH。发生这种情况的条件是当您的地址/掩码隐含的接口(暂时)未(正确)配置时。查看某些系统进程是否导致周期性网络变化。

回答 1 投票 0

无法从源代码构建图形增强库

我正在尝试使用 emscripten 从源代码构建 Boost。 我的一个可执行 CMake 项目依赖于以下 boost 库: 提升::提升 提升::文件系统 升压::程序选项

回答 1 投票 0

如何在动态容器中锁定可变数量的互斥锁?

类似问题: 使用 std::vector 调用 std::lock () 使用 std::lock_guard 数组锁定 std::mutex 数组 概括: 第二个显示锁定静态大小的数组,并且...

回答 1 投票 0

将 C++ lambda 函数转换为 boost 中的类方法函数

我是一名自学成才的 C++ 程序员,试图学习更多知识。 我正在尝试修改位于此处的 boost ssl 示例: https://www.boost.org/doc/libs/1_82_0/doc/html/boost_asio/example/cpp...

回答 1 投票 0

具有不同调用顺序的 boost::dynamic_bitset 的 [] 运算符的计算时间存在差异

我发现在 AWS EC2 实例(Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz)上调用 boost::dynamic_bitset 的 [] 运算符的计算时间存在变化。在下面的代码中,当

回答 1 投票 0

Boost R-tree - 如何有效地采样随机元素

我正在使用 boost 库 R 树将值存储在 2D 空间中。我正在尝试找到一种方法来有效地从 R 树中采样随机值。 到目前为止我已经尝试了2种方法来做到这一点,都有

回答 1 投票 0

使用 boost url 以与平台无关的方式将绝对文件系统路径转换为文件 URI

问题以与平台无关的方式将绝对文件系统路径转换为文件 URI 已经六岁了,现在我们有了 boost url https://www.boost.org/doc/libs/1_85_0/libs/url/doc/html/index.html....

回答 1 投票 0

Boost.Cobalt:如何退出生成器而不返回值

我正在将使用 Lewis Baker 的 cppcoro 库的代码转换为使用 Boost.Cobalt #包括 #包括 #包括 #包括 我正在将使用 Lewis Baker 的 cppcoro 库的代码转换为使用 Boost.Cobalt #include <cppcoro/generator.hpp> #include <iostream> #include <fstream> #include <string> cppcoro::generator<std::string> read_script_file(std::ifstream& script) { std::string line; while (std::getline(script, line)) { if (line.empty()) { continue; } if (line[0] == '#') { continue; } co_yield line; } } void print_script_file() { std::ifstream ifs("script"); for (const auto line : read_script_file(ifs)) { std::cout << line << "\n"; } } 这是 Boost.Cobalt 版本: #include <boost/cobalt.hpp> #include <fstream> #include <iostream> #include <string> boost::cobalt::generator<std::string> read_script_file(std::ifstream& script) { std::string line; while (std::getline(script, line)) { if (line.empty()) { continue; } if (line[0] == '#') { continue; } co_yield line; } co_return "--exit"; } void print_script_file() { std::ifstream ifs("script"); while (true) { const auto line = co_await read_script_file(ifs); if (line == "--exit") { break; } std::cout << line << "\n"; } } cppcoro 版本更加优雅,因为它不需要返回“--exit”字符串来完成 发电机。 有没有更好的方法来编写Boost.Cobalt版本? [1] cppcoro - https://github.com/lewissbaker/cppcoro [2] Boost.Cobalt - https://github.com/boostorg/cobalt 回答我自己的问题。 Boost.Cobalt 作者提供了回复[1]。 总之,从该协程不返回任何值是 UB(未定义行为)。 这是最终的完整示例: #include <boost/cobalt.hpp> #include <boost/cobalt/main.hpp> #include <fstream> #include <iostream> #include <string> boost::cobalt::generator<std::string> read_script_file(std::ifstream& script) { std::string line; while (std::getline(script, line)) { if (line.empty()) { continue; } if (line[0] == '#') { continue; } co_yield line; } co_return {}; } boost::cobalt::main co_main(int argc, char *argv[]) { try { std::ifstream script("script"); if (!script) { std::cerr << "ERR: failed to open " << argv[1] << "\n"; co_return 1; } auto g = read_script_file(script); while (g) { const auto line = co_await g; if (line.empty()) { break; } std::cout << "<" << line << ">\n"; } } catch (const std::exception& e) { std::cout << "Exception: " << e.what() << "\n"; } co_return 0; }

回答 1 投票 0

如何在 C++ 中验证 boost::locale::generator?

如何在 C++ 中验证 boost::locale::generator?我有以下代码,但它总是返回“区域设置名称:*”。 #包括 #包括 int main()...

回答 1 投票 0

读取 Boost Graph Library 中的 GraphML 文件时出现解析错误

我在使用 Boost Graph Library 读取 GraphML 文件时遇到问题。该文件创建时没有问题,但读回它会引发解析错误。以下是我正在做的事情的总结: 我创建我的

回答 1 投票 0

Conan 在 Windows 上使用 gcc 构建 cpp 项目

我一直很难让 conan 在我的 Windows 机器上使用 gcc 构建一个项目。 这就是我目前在柯南个人资料中的内容。 工具链=F:/tools/msys2/mingw64/bin 目标主机=...

回答 1 投票 0

如何跳过 BOOST 单元测试?

如何跳过 BOOST 单元测试?我想以编程方式跳过一些单元测试,具体取决于(例如)我执行它们的平台。我目前的解决方案是: #定义

回答 5 投票 0

如何在 Boost::Spirit::x3 中执行通用的可重用规则?

在我目前正在开发的解析器中,我正在编写一些规则/“子解析器”,其大小相当重要。问题是:因为这个解析器可能需要编译器付出一定的努力......

回答 1 投票 0

为什么 boost::function_output_iterator 不是 std::output_iterator?

我希望 boost::function_output_iterator 是一个 std::output_iterator,但令人惊讶的是不是: #包括 模板 我希望boost::function_output_iterator是一个std::output_iterator,但令人惊讶的是不是: #include <boost/iterator/function_output_iterator.hpp> template<std::output_iterator<int> IntOutIter> void f(IntOutIter outputIterator){} int main(int argc, char const *argv[]) { f(boost::make_function_output_iterator([](int i){})); return 0; } (注意,语法 template<std::output_iterator<int> IntOutIter> 来自 如何声明采用 T 的 output_iterator 的模板函数?) clang++ -std=c++20 function-output-iterator.cpp 错误: error: no matching function for call to 'f' note: candidate template ignored: constraints not satisfied [with IntOutIter = function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>] note: because 'std::output_iterator<boost::iterators::function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>, int>' evaluated to false note: because 'boost::iterators::function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>' does not satisfy 'input_or_output_iterator' note: because 'boost::iterators::function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>' does not satisfy 'weakly_incrementable' note: because 'iter_difference_t<function_output_iterator<(lambda at function-output-iterator.cpp:11:42)>>' (aka 'void') does not satisfy '__is_signed_integer_like' note: because 'void' does not satisfy 'signed_integral' note: because 'void' does not satisfy 'integral' note: because 'is_integral_v<void>' evaluated to false note: and 'void' does not satisfy '__is_signed_int128' note: because 'same_as<void, __int128>' evaluated to false note: because '__detail::__same_as<void, __int128>' evaluated to false note: because 'std::is_same_v<void, __int128>' evaluated to false note: and 'same_as<void, __max_diff_type>' evaluated to false note: because '__detail::__same_as<void, std::ranges::__detail::__max_diff_type>' evaluated to false note: because 'std::is_same_v<void, std::ranges::__detail::__max_diff_type>' evaluated to false 1 error generated. 疑似原因 我怀疑这是因为boost::function_output_iterator声明 typedef void difference_type; 但是标准说它需要是integral,而不是void: 成为 output_iterator 需要成为 weakly_incrementable(通过 input_or_output_iterator) this 表示 std::iter_difference_t<T> = ...::difference_type(在 Boost 代码中将 iter_difference_t 和 difference_type 联系起来) 这条评论指出标准requires is-signed-integer-like<iter_difference_t<I>>对于weakly_incrementable 常见的建议是将 difference_type 实施为 ptrdiff_t,而不是 void: 为什么 Difference_type 是 std::weakly_incrementable 概念的一部分? 当你无法测量差异时如何处理 iterator::difference_type? 解决方法和增强自己的主张 我知道这可以编译: -template<std::output_iterator<int> IntOutIter> +template<IntOutIter> void f(IntOutIter outputIterator){} 但它消除了 C++ 的好处concepts:限制泛型类型变量以获得更好的错误消息并指示它们应该支持哪些操作。 那么,function_output_iterator不应该是output_iterator吗? 此外,boost 文档声称: function_output_iterator 是 Writable 和 Incrementable 迭代器概念的模型。` 但是incrementable需要weakly_incrementable,它显然不是一个模型! 问题 那么,带来了什么? boost::function_output_iterator实施错误吗? 或者我不应该能够将它用作 output_iterator,并且 boost 文档是错误的? 这只是一个猜测——我不是那个特定 boost 库的作者(好吧,我不是任何 boost 库的作者......),或者与 boost 的联系比任何其他用户都多。 您链接的 boost 文档页面上的日期是 2006 年的,这表明它相当旧,并且早于 C++20,足以假设在创建库时,他们仍在开发 C++11。 Boost 通常在其文档中谈论很多概念,但它们(通常)不指 C++20 概念。他们使用该术语仅指类型属性表,例如 boost.org/doc/libs/1_85_0/libs/iterator/doc/...。这类似于 C++20 概念,但没有编译器支持。 Boosts 非正式概念和 STL 中的概念甚至可能具有相同的名称,但这并不意味着它们 100% 相同。也许该库的作者还没有时间将内容与 STL 保持一致。也许他们对现有代码存在兼容性问题。或者也许他们不再对该库做任何事情了。 我们都认为使事物符合 STL 是一个好主意,但实际工作不是我们:-)

回答 1 投票 0

Boost 使用 GCC 编译,但不使用 MinGW(使用 CMake)

所以我有一个 C++ 项目,用于从 JSON 文件生成一些批处理文件,我使用 CMake 构建该文件。我使用的是 Windows,但使用 WSL2 可以在 Linux 中完成所有操作。我已经开发了一切并构建了它......

回答 1 投票 0

使用 kNN 的自定义距离函数来提升 R 树

几天来,我一直在尝试弄清楚如何传递自定义距离函数来增强 R 树以进行 k 最近邻查询。 我有大量的线串和多边形。我将两者都嵌入...

回答 1 投票 0

用于单元测试的模拟 AsyncReadStream 增强

我面临着一种情况,我们在表示 HTTP 会话的类内部使用 http::async_read(...) 和 http::async_write(...) 。但是,如果我们想对这个类进行单元测试,我们会

回答 1 投票 0

在一个协程的子协程中使用 websocket 时卡在 co_await

我尝试在两个协程中使用一个 ws 对象,一个协程用于发送,另一个用于接收。然而,当我尝试在现有协程中使用子协程时,代码停留在

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.