boost 相关问题

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

具有不同调用顺序的 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

将 unique_ptr 传递给完成处理程序时,Boost ASIO“错误地址”错误

我正在尝试使用 ASIO 实现一个简单的 TCP 服务器。这里的主要区别是我使用 std::unique_ptr 来保存缓冲区而不是原始指针,并且我将它们移动到完整的内部...

回答 1 投票 0

适用于 Windows 操作系统的 strerror_r 替代 api

我看到 Visual C++ 2008 不再支持 strerror_r(...) API,可能是因为线程安全问题。我想在我的程序中使用类似的功能。 还有其他 winapi 吗...

回答 2 投票 0

如何强制 boost 以 root 身份运行时抛出 boost::filesystem::filesystem_error ?

我有一些代码可以在某些(难以重现)情况下引发 boost::filesystem::filesystem_error 异常。 我设置了异常处理程序,我想测试正确的

回答 1 投票 0

在boost中查找有向图的所有循环

有人可以告诉我如何使用boost图库找到有向图的所有循环吗?

回答 2 投票 0

如何使用与 io_context 一起使用的不同 TimerInterval 类在类中调用具有自己的采样间隔的不同方法

我正在尝试使用与本文中的问题答案相同的想法。这个目标是实现一个类,它将在 start_trigger 中调用 3 个不同的方法,并使用它们自己的时间间隔

回答 1 投票 0

从accumulator_set中删除或修改accumulators::tag

在boost中,是否可以从accumulator_set动态删除给定的boost::accumulators::tag? typedef boost::累加器::功能 < boost::accumulators::tag::count, boost::

回答 2 投票 0

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